开发者

I have a query that does 2 sums, and then the first will subtract the second, but in some cases the second is null

开发者 https://www.devze.com 2023-02-24 21:38 出处:网络
I have a query (in MS-Query, MSQRY32.EXE) that does 2 sums, and then the first will subtract the second, but in some cases the second is null, how do I go over this?

I have a query (in MS-Query, MSQRY32.EXE) that does 2 sums, and then the first will subtract the second, but in some cases the second is null, how do I go over this?

(Sum(CASE WHEN m.mcdmv=11 THEN m.mqtd END)- 
Sum(CASE WHEN m.mcdmv=12 THEN m.mqtd END))

This is the part of the query, but sometimes one of them or both a开发者_如何学运维re null, so how do I do this?


(IIf(Sum1 Is Null,0,Sum1) - IIf(Sum2 Is Null,0,Sum2))


First I'd ask whether it is appropriate to be summing nulls, and what you expect to get when you subtract a null from an non-null (or vice-versa).

Probably what you want to do is either eliminate records with nulls (where m.mqtd is not null) or to change all the null's to 0's (nz(m.mqtd, 0))

0

精彩评论

暂无评论...
验证码 换一张
取 消