Count for all table

s imam 21 Reputation points
2021-03-18T15:49:47.46+00:00

I have 10 tables. I want count, sum, group, min, max and average for each table. Right now I am running below scripts one by one for each table. I wonder if it possible to run the script for all the tables. -- Count of record Select count(*) as RecordsTotal From table1 Where substring(ID,12,1)='9' and Year > '2016' -- Sum of Pages Select sum(cast(pages as INT) as PageCount from table1 Where substring(ID,12,1)='9' and Year > '2016' --Group by pages (0-25, 25-50,.....) Select sum(cast(pages as INT) as Rage from table1 Where substring(ID,12,1)='9' and Year > '2016' Group by --Min Select Min(cast(pages as INT) as minPages from table1 Where substring(ID,12,1)='9' and Year > '2016' --Max Select Min(cast(pages as INT) as maxPages from table1 Where substring(ID,12,1)='9' and Year > '2016' --AVG Select AVG(cast(pages as INT) as AVGPages from table1 Where substring(ID,12,1)='9' and Year > '2016'

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,558 questions
{count} votes