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.