[英]SQL table LEFT OUTER join query
The reason is that NULL
is not the same as 0. Try this: 原因是
NULL
与0不同。请尝试以下操作:
P.Quantity-COALESCE(S.Quantity,0) AS ClosingQty
See here: http://www.w3schools.com/sql/sql_isnull.asp 看到这里: http : //www.w3schools.com/sql/sql_isnull.asp
Your solution is failing as S.QUANTITY is NULL, so any arithmetic on it will result in a NULL answer. 您的解决方案失败了,因为S.QUANTITY为NULL,因此对其进行任何算术运算都将导致NULL答案。 You will need to check for null, and replace with a valid number, for example 0.
您将需要检查是否为空,并替换为有效数字,例如0。
The following should work: 以下应该工作:
ISNULL(P.QUANTITY,0) - ISNULL(S.QUANTITY, 0) AS ClosingQty
The real question, though, is why is S.QUANTITY null in the first place? 但是,真正的问题是,为什么S.QUANTITY首先为null?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.