I try to use case statement in where clause in sql server and get the error message.
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
maybe because the PRCA.Class have two condition? or i just do not write CASE Statement right.
Dump the case statement. Use this:
AND (UPPER(PRCA.CLASS) not like '%PREAPR%' OR @ExcludePREAPR != 'Y')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.