0

Is there a way in SQL Server to accomplish the following (execute a query as a column using the results from another column)?

use mydb
go

select 
    a.*,
    select count(*) from a.table_name
from 
    (select 
         (select version from mydb.version) as AppVersion,  
         table_Schema, table_name
     from 
         information_schema.tables
     where 
         table_type = 'BASE TABLE' 
         and TABLE_CATALOG = db_name()) as a
order by 
    a.table_name
Dale K
  • 25,246
  • 15
  • 42
  • 71
ssou
  • 21
  • 3
  • 1
    Yip - dynamic SQL... – Dale K May 31 '23 at 21:03
  • Is this what you're looking for? https://stackoverflow.com/a/34989683/2665139 – Tuan Pham May 31 '23 at 21:04
  • If all you want is row counts, there are more direct approaches such as [this answer](https://stackoverflow.com/a/14163881/12637193) and various other answers to "[sql-server row counts](https://stackoverflow.com/search?q=%5Bsql-server%5D+row+counts)" questions. – T N May 31 '23 at 21:16
  • If you want a count of all rows per table don't actually count them use `sys.dm_db_partition_stats` – Stu May 31 '23 at 21:42

0 Answers0