I have a table with ~150 columns. I\'d like to find the count(distinct(colName)) for each column but am wondering if there\'s a way to do so without actually t
count(distinct(colName))
You can do this:
DECLARE @query varchar(max) SELECT @query = 'SELECT ' + SUBSTRING((SELECT ',' +'COUNT(DISTINCT(' + column_name + ')) As ' + column_name + ' ' FROM information_schema.columns WHERE table_name = 'table_name' for xml path('')),2,200000) + 'FROM table_name' PRINT(@query)