Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Sql Procedure with/without cursor

Please help me with a simple procedure, lets say on Sql Server (2005, 2008, does not matter).

I have table dbo.[columns] with 1000 lines, which all are the names for some specific table names from a database.

Bottom line is that I need to create a procedure which will parse all 1000 lines of tables, for each table name found in dbo.[columns] to execute the following

select: select count(*), ''''+[column_name]+'''' from dbo.[column_name]

The result should be like this:

count(*)    table_name:
100          employees 
0            ex_employees
25           addresses
10           birthdays

Any hints?

Thanks in advance, Bogdan

like image 582
BogdanM Avatar asked Feb 05 '26 08:02

BogdanM


1 Answers

SELECT  COUNT(Column_With_List_Of_Table_Names_Here)
        , Column_With_List_Of_Table_Names_Here
FROM    YourDatabase.dbo.YourTable
GROUP BY Column_With_List_Of_Table_Names_Here;
like image 146
HarrisonC Avatar answered Feb 06 '26 20:02

HarrisonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!