how to this query in right syntax or right way?
i write this query using t-sql and give me an error (Incorrect syntax near the keyword 'OR') How to write it in correct way ?
SEL开发者_开发问答ECT SUM(Quantity) 
  FROM   Invoices
 WHERE  Invoices.InvoiceDocStatusID = 
        CASE @InventoryType
                      WHEN 1 
                      THEN ((2)OR(1))
                      ELSE 2
                    END
Not really that certain of the desired semantics. Do you always want rows matching InvoiceDocStatusID=2 regardless of the value of @InventoryType and additionally want InvoiceDocStatusID=1 where @InventoryType = 1?
SELECT SUM(Quantity) 
  FROM   Invoices
 WHERE  (Invoices.InvoiceDocStatusID = 1 AND @InventoryType = 1)
OR Invoices.InvoiceDocStatusID = 2
- You're always checking for Invoices.InvoiceDocStatusID = 2
- The only switch is on @InventoryType
- No ELSE clause is needed: it goes to NULL
So...
SELECT SUM(Quantity) 
FROM Invoices
WHERE Invoices.InvoiceDocStatusID IN (2, CASE @InventoryType WHEN 1 THEN 1 END)
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论