我收到错误'>'附近的语法不正确 每个字段都包含十进制值,NOT NULL和默认值为零。 我尝试了不同的括号,我相信我只是错过了CASE声明的格式。
AND CASE WHEN QtyIssued <> 0 OR WM.QtyToMake <> 0 OR WMat.UnitQtyReqd <> 0 THEN QtyIssued/WM.QtyToMake * WMat.UnitQtyReqd >= .68 ELSE 0 END
我需要在每个值中检查零,所以我没有除以零
下面列出了整个SQL:
SELECT SUBSTRING([SalesOrder], PATINDEX('%[^0]%', [SalesOrder]+'|'), LEN([SalesOrder])) AS SO, WM.SalesOrderLine AS SOLine,
SUBSTRING(WM.Job, PATINDEX('%[^0]%', WM.Job+'|'), LEN(WM.Job)) AS Job, WMat.StockCode, --WM.QtyToMake * WMat.UnitQtyReqd AS Qty2IssuedValue,
CEILING(WM.QtyToMake * WMat.UnitQtyReqd) AS Qty2Issue,
CEILING(WMat.QtyIssued) AS QtyIssued, WMP.WipRelease, WM.JobTenderDate,
WM.Complete ,
CASE WHEN QtyIssued = 0 OR WM.QtyToMake = 0 OR WMat.UnitQtyReqd = 0
THEN 0 ELSE (QtyIssued/(WM.QtyToMake * WMat.UnitQtyReqd)) END AS QtyNotAllocated
FROM dbo.WipMaster AS WM INNER JOIN
dbo.[WipMaster+] AS WMP ON WM.Job = WMP.Job FULL OUTER JOIN
dbo.WipJobAllMat AS WMat ON WM.Job = WMat.Job
WHERE (WMP.WipRelease BETWEEN CONVERT(DATETIME, '2016-04-01 00:00:00', 102) AND
CONVERT(DATETIME, '2016-04-29 00:00:00', 102))
AND CASE WHEN QtyIssued <> 0 OR WM.QtyToMake <> 0 OR WMat.UnitQtyReqd <> 0 THEN QtyIssued/WM.QtyToMake * WMat.UnitQtyReqd >= .68 ELSE 0 END
答案 0 :(得分:0)
case
中的where
是:
(CASE WHEN QtyIssued <> 0 OR WM.QtyToMake <> 0 OR WMat.UnitQtyReqd <> 0
THEN QtyIssued/WM.QtyToMake * WMat.UnitQtyReqd >= .68
ELSE 0
END)
这不是布尔表达式。我甚至不确定你的意图。也许:
((QtyIssued <> 0 OR WM.QtyToMake <> 0 OR WMat.UnitQtyReqd <> 0) AND
QtyIssued/NULLIF(WM.QtyToMake, 0) * WMat.UnitQtyReqd >= .68
)
NULLIF()
可以防止除以零。