将null 换成0
下面是写的行转列的语句,如何将指为NULL的用0替换掉,谢谢
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')
------------------
SPH00000001NULLNULLNULLNULLNULLNULLNULLNULLNULL
SPH0000000211.00NULLNULLNULLNULLNULLNULLNULL9.00
SPH000000031.00NULLNULLNULLNULLNULLNULLNULLNULL
SPH00000004NULLNULLNULLNULLNULLNULLNULLNULLNULL
SPH00000005NULLNULLNULLNULLNULLNULLNULLNULLNULL
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')