开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜