SQL Server 2005 Error - “”MAX“ is not a recognized table hints option”
问题 I am trying to use dynamic SQL to do a pivot on a table for which I need to dynamically generate the column names. My code is: DECLARE @columns varchar(max) DECLARE @query varchar(max) SELECT @columns = COALESCE(@columns + ',[' + cast([Name] as varchar(max)) + ']', '[' + cast([Name] as varchar(max))+ ']') FROM dbo.Temp2 SET @query = 'SELECT * FROM dbo.Temp2 AS PivotData' SET @query = @query + 'PIVOT (MAX(VALUE) FOR [NAME] IN (' + @columns + ')) AS p' EXEC (@query) My @columns function seems