我使用t-sql编写此查询并给我一个错误(关键字'OR'附近的语法不正确) 如何以正确的方式写出来?
SELECT SUM(Quantity)
FROM Invoices
WHERE Invoices.InvoiceDocStatusID =
CASE @InventoryType
WHEN 1
THEN ((2)OR(1))
ELSE 2
END
答案 0 :(得分:2)
不是那种确定的语义。您是否总是希望与InvoiceDocStatusID=2
匹配@InventoryType
的行,而不管InvoiceDocStatusID=1
的价值是什么?另外还要@InventoryType = 1
哪里有SELECT SUM(Quantity)
FROM Invoices
WHERE (Invoices.InvoiceDocStatusID = 1 AND @InventoryType = 1)
OR Invoices.InvoiceDocStatusID = 2
?
{{1}}
答案 1 :(得分:1)
因此...
SELECT SUM(Quantity)
FROM Invoices
WHERE Invoices.InvoiceDocStatusID IN (2, CASE @InventoryType WHEN 1 THEN 1 END)