Declare @ColumnName nvarchar(max) Declare @SQLQuery nvarchar(max) select @ColumnName=STUFF((select distinct \',[\'+ cast(Month as nvarchar)+\']\' from Food for xml