0

我有这个更新 SQL:

UPDATE  o
SET     HolidayPay = lob.AllowHolidayPay ,
        AppreciationPay = lob.AllowAppreciationPay
FROM    Orders AS o
        INNER JOIN LineofBusiness AS lob ON o.LineofBusinessID = lob.LineofBusinessID
WHERE   o.StatusID != 156 -- ALL ORDERS THAT ARE NOT CLOSED
        AND o.TempOrDirect = 'T'
GO

我需要让 WHERE 子句不仅仅使用 statusID。需要发生的是如果 statusID = 156,那么它还需要检查 stageID 的值。因此,如果 statusID = 156,但 stageID = 6,那没关系。如果 statusID 仍然是 156 但 stageID 是任何其他值,则观察到 != 部分。

提前致谢!

4

2 回答 2

1

采用

(o.StatusID != 156 OR (o.StageID=6 and o.StatusID=156))
于 2013-04-28T02:10:34.157 回答
1

那么 stageID = 6 还是 StatusID != 156?

WHERE (o.StatusID != 156 
        OR stageID = 6)
    AND o.TempOrDirect = 'T'
于 2013-04-28T02:10:48.087 回答