Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generate SQL Statements to Group By Each Column of Table Separately
declare @table_name varchar(200) = 'dbo.mytablename'
'select ' + + ', count(1) cnt from ' + @table_name + ' group by ' + + ' order by 2 '
from sys.columns c
where c.object_id = object_id(@table_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.