Above, I believe the following SQL should work. It will execute a query for each combination of columns and columns, and the query will return the table name and column name if there are no rows or all zero rows in this combination of columns and columns.
DECLARE @table_columns TABLE ( table_name nvarchar(128), column_name nvarchar(128) ); DECLARE @table_name nvarchar(128); DECLARE @column_name nvarchar(128); INSERT INTO @table_columns(table_name, column_name) select TABLE_NAME, COLUMN_NAME from INFORMATION_SCHEMA.columns; while (select count(*) from @table_columns) > 0 begin select top 1 @table_name = table_name, @column_name = column_name from @table_columns exec('SELECT ''' + @table_name + ''' as table_name, ''' + @column_name + ''' as column_name WHERE NOT EXISTS (SELECT TOP 1 * FROM ' + @table_name + ' WHERE ' + @column_name + ' IS NOT NULL)') delete from @table_columns where table_name = @table_name and column_name = @column_name end
Nullpointerinterception
source share