I don't exactly know how to articulate this question, so apology if this has been asked before. Here I have this query to pivot a table: SELECT * FROM ( SELECT [cashValue], [Name], [t] FROM [DBName].[dbo].[TableName]) AS SourceTable PIVOT (max([cashValue]) FOR [t] IN ([1],[2],[3]) ) AS PivotTable Notice I have the "[1],[2],[3]" when I need to generate the column name? My [t] has value spanning from 1 to 51. Can I just write a loop to generate [1] all the way to [51] ? Thanks Continue reading...