SQLServer中的条件WHERE子句我正在创建一个SQL查询,其中我需要一个条件。where条款。应该是这样的:SELECT
DateAppr,
TimeAppr,
TAT,
LaserLTR,
Permit,
LtrPrinter,
JobName,
JobNumber,
JobDesc,
ActQty,
(ActQty-LtrPrinted) AS L,
(ActQty-QtyInserted) AS M,
((ActQty-LtrPrinted)-(ActQty-QtyInserted)) AS NFROM
[test].[dbo].[MM]WHERE
DateDropped = 0
--This is where i need the conditional clause
AND CASE
WHEN @JobsOnHold = 1 THEN DateAppr >= 0
ELSE DateAppr != 0
END以上查询不起作用。这不是正确的语法吗,还是我不知道的另一种方法?我不想使用动态SQL,那么还有其他方法吗?还是必须使用解决办法,比如使用if else和使用相同的查询where条款?
3 回答
慕勒3428872
TA贡献1848条经验 获得超6个赞
SELECT DateAppr, TimeAppr, TAT, LaserLTR, Permit, LtrPrinter, JobName, JobNumber, JobDesc, ActQty, (ActQty-LtrPrinted) AS L, (ActQty-QtyInserted) AS M, ((ActQty-LtrPrinted)-(ActQty-QtyInserted)) AS NFROM [test].[dbo].[MM]WHERE DateDropped = 0 AND ( (ISNULL(@JobsOnHold, 0) = 1 AND DateAppr >= 0) OR (ISNULL(@JobsOnHold, 0) != 1 AND DateAppr != 0) )
MYYA
TA贡献1868条经验 获得超4个赞
WHERE DateDropped = 0 AND ( (ISNULL(@JobsOnHold, 0) = 1 AND DateAppr >= 0) OR (ISNULL(@JobsOnHold, 0) != 1 AND DateAppr != 0) )
- 3 回答
- 0 关注
- 616 浏览
添加回答
举报
0/150
提交
取消