I wanted to consult on a subject that I could not carry out. I am starting the query load through SQL for SAP, and I cannot perform a CASE where it asks for the employee number, and according to the employee number, it loads me with the name of the vendor that corresponds to that vendor number.
Thank you very much in advance for any contribution to resolve this question.
I leave the syntax here
SELECT T0."CardName",
T0."LicTradNum",
T0."GroupNum",
T1."GroupNum",
T2."InstNum",
T2."PaymntsNum",
T2."VolumDscnt",
T1."Comments",
T3."OwnerCode",
T1."CntrlBnk",
T1."SlpCode",
T1."PeyMethod"
CASE t1."SlpCode"
WHEN -1 THEN 'VENDEDOR 1 '
WHEN 2 THEN 'VENDEDOR 1 '
WHEN 3 THEN 'VENDEDOR 1 '
WHEN 7 THEN 'VENDEDOR 1 '
END
FROM OCRD T0
INNER JOIN OQUT T1 ON T0."CardCode" = T1."CardCode"
INNER JOIN OCTG T2 ON T0."GroupNum" = T2."GroupNum"
INNER JOIN OINV T3 ON T1."CardName" = T3."CardName"
WHERE T1."GroupNum" = 7
In the correction, add the comma (,) after the last field of the table, and do the THEN for each corresponding case of the SlpCode:
It's just a syntax error. The declaration of a CASE inside a SELECT is valid in this way:
CASE ProductLine
WHEN 'R' THEN 'Road'
WHEN 'M' THEN 'Mountain'
WHEN 'T' THEN 'Touring'
WHEN 'S' THEN 'Other sale items'
ELSE 'Not for sale'
END
https://social.msdn.microsoft.com/Forums/es-ES/969f0434-15ef-43de-9ba9-7510974a6145/case-inside-select?forum=sqlserveres