日期:2014-05-18 浏览次数:20538 次
if object_id('tempdb..#test') is not null drop table #test; declare @sql varchar(8000),@sql1 varchar(8000) select @sql = isnull(@sql + ',' , '') + fdepartname1 from mm group by fdepartname1 select @sql1 = isnull(@sql1 + ',' , '') + fdepartname2 from mm group by fdepartname2 exec (' select * into #test from (select * from mm) a pivot (max(fbysl) for fdepartname1 in (' + @sql + ') ) b pivot (max(fbyje) for fdepartname2 in (' + @sql1 + ') ) c ')
------解决方案--------------------
insert into tb select * from (select * from mm) a pivot (max(fbysl) for fdepartname1 in (' + @sql + ') ) b pivot (max(fbyje) for fdepartname2 in (' + @sql1 + ') ) c