Reputation: 786
I have a very peculiar problem on my hands. I have a project where the previous db engineer didn't gave a thought on db design and now im stuck with it. My question is simple:
I have two different select queries and one of them should be executed if a field is set or not, i.e.
if field1 is 0 -> execute query 1 if field1 is 1 -> execute query 2
So far i got here:
SELECT should_i_care
FROM
product_sample
WHERE
pid='XXX'
CASE should_i_care
WHEN '1' then call query2
WHEN '0' then call query1
But found out that i cant declare the queries i want to run. Any suggestions?
Upvotes: 1
Views: 829
Reputation: 8239
It should be a script or stored procedure like this
DECLARE shouldICare INT;
SELECT @shouldICare := should_i_care
FROM
product_sample
WHERE
pid='XXX';
IF @shouldICare = 1 THEN
Call query2;
ELSE
Call query1;
END IF;
Upvotes: 1