竖表横向转换,核心:declare @s varchar(8000)set @s=''select @s=@s+',['+field1+']=max(case field1 when '''+field1+''' then data else '''' end)' from(select distinct field1 from #t) a