1

我有一个“特殊情况”需要在sql脚本中考虑。这是我到目前为止所拥有的,我“认为”它有效,但看起来很乱。它sproc假设有一个@empStatus参数。如果员工的@empStatus=2我想用Statusof1或退回所有员工的2

select *
from Employees
where Title='Associate' and Status=@empStatus and Department='Sales'
    OR (@empStatus=2 and (Status=@empStatus or Status=1) and Title='Associate' and Department='Sales')
4

1 回答 1

4

这应该涵盖它

SELECT 
    *
FROM
    Employees
WHERE
   Title='Associate'
   AND Department='Sales'
   AND ((Status=@empStatus) OR (@empStatus=2 AND Status=1))
于 2012-12-21T00:40:46.953 回答