In some of my procedures I'm passing parameter that should determine whether I need INNER
or LEFT
join but unfortunately I don't have an idea how can I implement it.
The easiest solution of course is to have an IF
statement and check for the parameters value and use according query on it but it does seem like a bit of overkill -> my query joins over 30 tables so it would be a bummer if I had to copy it just to have one word changed.
What I need is something like (yes, I know it doesn't work):
SELECT a.ID,
a.NAME,
b.TYPE
FROM A
CASE
WHEN :ip_param = 'I' THEN INNER JOIN B ON A.ID2 = B.ID
ELSE LEFT JOIN B ON A.ID2 = B.ID
END
Would be grateful for any hints/ideas how to solve it differently then having:
IF :ip_param = 'I' THEN
select with inner join
ELSE
select with left join
END IF