Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Just_Jeff
Starting Member
7 Posts |
Posted - 2011-11-14 : 18:24:59
|
| I want to create a query that will show the number of records in each column that has a NULL value for each table in my database.I've got the first part figured out. select t.TABLE_NAME ,c.COLUMN_NAMEfrom INFORMATION_SCHEMA.TABLES t inner join INFORMATION_SCHEMA.COLUMNS c on (t.TABLE_NAME = c.TABLE_NAME)where t.TABLE_CATALOG = 'MyDB'order by t.TABLE_NAME, c.COLUMN_NAMENow I need to squeeze the following query into the previous SQL statement so that it operates on each row returned:select count(*) from currentTable where currentColumn is NULLThe end product should be a big list with all the tables, each column in those tables and the row counts of null values in each column.I'm sure the query is something simple but I don't seem to be able to get it to work for each row. Thanks,-Jeff |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Just_Jeff
Starting Member
7 Posts |
Posted - 2011-11-14 : 18:56:41
|
| That's sort of what I'm after but I'd like it to execute each one of those statements and return just 3 columns. Table, column, null record count. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Just_Jeff
Starting Member
7 Posts |
Posted - 2011-11-14 : 19:13:53
|
| The problem is that it returns a resultset for each sql statement. That gives me 678 recordsets and that isn't going to work very well for this project. Even throwing in a union statement between all of the statements isn't a very elegant solution.There must be a way to run a subquery within the main query. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|