SQL-Server getting list of columns that doesn't contains any value
When having table with large number of columns, it may be helpful to find if there are columns that doesn't contains any value. You can use the following query to achieve this (Just replace 'dbo.MyTable' with your table name) Query steps: 1- Getting all columns count using one select query and giving an alias the original column name for each count column 2- Pivoting Result Table into a Temp table 3- Selecting Columns that have a Count = 0 from Temp Table DECLARE @ strTablename varchar ( 100 ) = 'dbo.MyTable' DECLARE @ strQuery varchar ( max ) = '' DECLARE @ strUnPivot as varchar ( max ) = ' UNPIVOT ([Count] for [Column] IN (' CREATE TABLE ## tblTemp ([ Column ] varchar ( 50 ), [ Count ] Int ) SELECT @ strQuery = ISNULL (@ strQuery , '' ) + 'Count([' + name + ']) as [' + name + '] ,' from sys . columns where object_id = object_id (@ strTablename ) and is_nullable