0
WHERE
--from TABLE.PARAMETER1
    (b.is_ot_paycode = 'Y' OR 
-- from variableA
    b.is_ot_paycode = 'Y')
    AND
-- from TABLE.PARAMETER1
    (b.is_wh_paycode = 'Y'  OR 
-- from variableA
    b.is_wh_paycode = 'Y') 
-- from variableB
    AND b.is_ot_paycode = 'Y' 

如何CASE在我的WHERE子句中创建一个语句,当

b.is_wh_paycode = 'Y' (from variableA) and 
b.is_ot_paycode = 'Y'(from variableB) 
b.is_wh_paycode (from TABLE.PARAMETER1) would always be equal to 'N'?   
4

1 回答 1

1

你不需要一个case

WHERE (b.is_wh_paycode <> 'Y' or b.is_ot_paycode <> 'Y' or b.is_wh_paycode = 'N')

你可以把它写成case

WHERE b.is_wh_paycode = (case when b.is_wh_paycode = 'Y' and b.is_ot_paycode = 'Y' 
                              then 'N' else b.is_wh_paycode
                         end)

但不一定更清楚。

注意:这两个都假设列不采用NULL值。如果他们这样做,那么 SQL 将需要考虑到这一点。

于 2013-09-16T15:14:14.637 回答