我尝试在sql server中的where子句中使用case语句并获取错误消息。
WHERE (PRCA.EDLType = 'E')
AND
(
NOT
(
PRCA.EDLCode IN
(
SELECT EarnCode
FROM dbo.udECforUnionRpt
WHERE (EDL = 'E')
)
)
)
AND (PRCM.udMasterCraft IS NOT NULL)
AND (PRCA.PREndDate BETWEEN @BegPREndDate AND @EndPREndDate)
AND PRCM.udMasterCraft BETWEEN @BegMasterCraft AND @EndMasterCraft
AND PRCA.Class BETWEEN @BegClass AND @EndClass
AND
(
CASE WHEN @ExcludePREAPR='Y' THEN UPPER(PRCA.Class) not like upper('%PREAPR%')
else PRCA.Class
)
END
)
ORDER BY PRCA.PRCo
也许是因为PRCA.Class有两个条件?或者我只是不写CASE声明。
答案 0 :(得分:3)
转储案例陈述。使用此:
AND (UPPER(PRCA.CLASS) not like '%PREAPR%' OR @ExcludePREAPR != 'Y')