日期:2014-05-17 浏览次数:20639 次
DECLARE @col VARCHAR(max) SELECT @col=ISNULL(@col+',','')+QUOTENAME([name]) FROM [tb] GROUP BY [name] EXEC('selcet * into newtable from(SELECT * FROM [tb] PIVOT(MAX([id]) FOR [name] IN ('+@col+') ) piv) as t where 1=2') SELECT * FROM newtable