Mssql 行转列
declare @sql varchar(8000) set @sql='' --初始化变量@sql select @sql=@sql+','+name from dbo.T_WF_WORKNODE where wfid='3237' and flag=0 --变量多值赋值 set @sql=stuff(@sql,1,1,'')--去掉首个',' set @sql=' select * from( select objectid,name,jyje from t_operate) t pivot (max(jyje) for name in ('+@sql+'))a' print @sql exec(@sql)
http://www.cnblogs.com/lrzy/p/6268067.html