pa.fdpayadjamount表有几个不同的类别(存款,付款等)。我想要做的是汇总所有存款和存款不存在的地方,使金额自动输入$ 0或null。有人可以帮我这个吗?谢谢!
SELECT ca.fdorgunit AS Facility
, pt.fdmedrecnum AS Account
, ca.fddos AS DOS
, Cast(iv.fdinnetdeposit/100.0 as decimal(10,2)) AS [Deposit Required]
, Cast(Sum(pa.fdpayadjamount)/100.0 as decimal(10,2)) AS Deposit
FROM OPENQUERY (VISION, 'SELECT * FROM de.tbinsverification') AS iv
LEFT JOIN OPENQUERY (VISION, 'SELECT * FROM ci.tbcase') AS ca
ON iv.fdcase = ca.id
JOIN OPENQUERY (VISION, 'SELECT * FROM de.tbpatient') AS pt
ON pt.id = ca.fdpatient
LEFT JOIN OPENQUERY (VISION, 'SELECT * FROM ar.tbpayadjmaster') AS pa
ON pa.fdpatient = pt.id
WHERE iv.fdinnetdeposit is not Null AND iv.fdinnetdeposit <> '0' AND ca.fdcasestatus = 'Performed' AND pa.fdledgercodetype = 'Deposit'
GROUP BY ca.fdorgunit, ca.fddos, iv.fdinnetdeposit, pt.fdmedrecnum
答案 0 :(得分:1)
也许你只需要在第五行添加ISNULL()函数就好了。
, Cast(ISNULL(Sum(pa.fdpayadjamount),0)/100.0 as decimal(10,2)) AS Deposit
答案 1 :(得分:0)
您可以尝试使用此代码来处理总和。
isnull(Cast(sum(pa.fdpayadjamount)/100.0 as decimal(10,2)),0)AS Deposit
答案 2 :(得分:0)
这实际上解决了我自己的问题:
, Sum(Case When pa.fddescription = 'Deposit' Then Cast(pa.fdpayadjamount/100.0 as decimal(10,2)) Else 0 END) AS Deposit