0

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

4

1 回答 1

3

转储案例陈述。用这个:

AND (UPPER(PRCA.CLASS) not like '%PREAPR%' OR @ExcludePREAPR != 'Y')
于 2013-07-11T15:02:02.710 回答