日期:2014-05-17 浏览次数:20449 次
declare @sql varchar(8000)
select @sql=isnull(@sql+'],[' , '') + fdbs from daysphz group by fdbs
set @sql='['+@sql+']'
exec ('select * from (select spid,shl,fdbs from daysphz ) a pivot (sum(shl) for fdbs in ('+@sql+'))b
order by spid')
------------------
SPH00000001 NULL NULL NULL NULL NULL NULL NULL NULL NULL
SPH00000002 11.00 NULL NULL NULL NULL NULL NULL NULL 9.00
SPH00000003 1.00 NULL NULL NULL NULL NULL NULL NULL NULL
SPH00000004 NULL NULL NULL NULL NULL NULL NULL NULL NULL
SPH00000005 NULL NULL NULL NULL NULL NULL NULL NULL NULL
declare @sql varchar(8000)
select @sql=isnull(@sql+'],[' , '') + fdbs from daysphz group by fdbs
set @sql='['+@sql+']'
exec ('select * from (select isnull(spid,0),isnull(shl,0),isnull(fdbs,0) from daysphz ) a pivot (sum(shl) for fdbs in ('+@sql+'))b
order by spid')