Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin.
Search for scripts directly from SSMS, and instantly access any saved scripts in your
SSC briefcase from the favorites tab.
Download now (direct download link)
Thank this author by sharing:
UberCrossTab was created out of a need to create crosstab data as easily as MS Access does. It leverages SQL Server 2005's PIVOT function so it will NOT work in SQL Server 2000.
So, if you had a table setup like...
To get a crosstab showing Type as the rows and Color as the columns counting on ID you would use...
Note: The YOURDB reference is not needed if you stored the proc in the same database as your table.
@pivotRowFields = 'Type'
,@pivotField = 'Color'
,@pivotTable = '[YOURDB].[dbo].[Table1]'
,@aggField = 'ID'
,@aggFunc = 'COUNT'
I hope this can be of use to some.
Count Distinct in PIVOT
How to creat a color parameter