2016-05-02 79 views
0

我收到錯誤'>'附近的語法不正確 每個字段都包含十進制值,其中NOT NULL和默認值爲零。 我試過不同的括號,我相信我只是在某處忘記了CASE語句的格式。SQL 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

casewhere是:

(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()防止被零除。

+0

我要去的是吃我的蛋糕,也吃了它。 LOL –

+0

我想查看列中具有零值的那些,但沒有除以零的問題。所以,這裏是我想出的...對不起,新的論壇和工作如何使用它... –

+0

AND((QtyIssued <> 0或WM.QtyToMake <> 0或WMat.UnitQtyReqd <> 0 )AND \t \t \t \t \t \t \t \t \t QtyIssued/NULLIF(WM.QtyToMake,0)* WMat.UnitQtyReqd> = 0.68 OR \t \t \t \t \t \t \t \t \t QtyIssued = 0 OR WM.QtyToMake * WMat .UnitQtyReqd = 0 –