I'm currently in the process of writing a stored procedure that uses case statements to determine what queries to run. Inside one of my queries is a case expression and I get a syntax error every time I try to save the altered procedure. The procedure will save fine without that case expression, but fails once it is added. I know the syntax of the expression itself is accurate, so I'm wondering if case expressions are even allowed inside of a case statement.
Example:
CASE
WHEN x = 1 THEN
SELECT
5 AS 'Col1',
CASE
WHEN y = 5 THEN 2
ELSE 0
END AS 'Col2'
FROM table
WHERE 1=1
;
WHEN x = 2 THEN
SELECT
*
FROM table2
;
ELSE
SELECT
*
FROM table3
;
END CASE;
Any help would be greatly appreciated. Is it possible to have a case expression inside a case statement? If so, is it formatted differently? How can I get this to work...?
Thank you!