我尝试在 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 声明。