sql server - Converting NULLs to 0 in SQL Pivot -
the following code generates pivot (shown below code)
select * ( select glaccount , dc , amount accountingtxns acctno = '178523' ) tabledata pivot ( sum (amount) dc in ([d],[c]) ) sumamountdc glaccount d c interestdue 3801.37 3731.68 cash 25600 25000 intreceivable 3801.37 3801.37 intincome null 3684.47 intoverdue null 116.9 principal 25000 21868.32
how rid of nulls (i.e. convert them 0's)?
use coalesce,
select glaccount, coalesce(d, 0) d, coalesce(c, 0) c ( select glaccount, dc , amount accountingtxns acctno = '178523' ) tabledata pivot ( sum(amount) dc in ([d],[c]) ) sumamountdc
Comments
Post a Comment