CASE with IN does not work

2

I want to do this search below:

DECLARE @codccu VARCHAR(10);

SET @CodCcu = '63'
  SELECT E.codepi, 
             E.numcad, 
             Max(E.datent)            AS ENTREGA, 
             Max(E.datent) + P.diaval AS VALIDADE, 
             CASE 
               WHEN Max(E.datent) + P.diaval <= Getdate() THEN 'VENCIDO' 
               ELSE 'OK' 
             END              AS SITUACAO 
      FROM   r096die E, 
             r096epi P 
      WHERE  E.numcad = 241 
             AND 
                CASE  
                    WHEN @codccu IN ('911003','63') THEN E.codepi IN (1,6,23,24) 
                    ELSE E.codepi IN (1,23)
                END                         
             AND P.codepi = E.codepi 
      GROUP  BY E.codepi, 
                E.numcad, 
                P.diaval 

If I want to search the codEpi (1,6,23,24) if the cost center is ('911003','63') , if I do not want you to list the codes with the numbers (1,23)

But it displays the following error:

  

Incorrect syntax next to the keyword 'IN'. Error 156. SQLSTATE 42000. Severity 15. MsgState 1. Line 18.

What this line is about:

WHEN @codccu IN ('911003','63') THEN E.codepi IN (1,6,23,24) 

I've already researched and can not find where I'm going wrong in this script, I already tried it as follows:

AND E.codepi =
                CASE  
                    WHEN @codccu IN ('911003','63') THEN IN (1,6,23,24) 
                    ELSE  IN (1,23)
                END      

but has the same error.

    
asked by anonymous 01.06.2017 / 14:56

1 answer

3

You can not use IN in the result of a CASE . Replace with a structure with OR :

WHERE  E.numcad = 241 
  AND ((@codccu IN ('911003','63') AND E.codepi IN (1,6,23,24))
   OR (E.codepi IN (1,23)))        
  AND P.codepi = E.codepi 
    
01.06.2017 / 15:09