Created
March 15, 2016 21:02
-
-
Save aaronhoffman/d49d3705fd716b0fe6cb to your computer and use it in GitHub Desktop.
Generate SQL Statements to Group By Each Column of Table Separately
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @table_name varchar(200) = 'dbo.mytablename' | |
select | |
'select ' + c.name + ', count(1) cnt from ' + @table_name + ' group by ' + c.name + ' 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