Is there such a thing as conditional join:
SELECT *
FROM TABLE1 A
IF (a=='TABLE2') THEN INNER JOIN TABLE2 B ON A.item_id=B.id
ELSE IF (a=='TABLE3') THEN INNER JOIN TABLE3 C ON A.item_id=C.id
So far this field is in table 1.
I like to use this in stored procedures without using dynamic sql (without writing the query as a string and EXEC (@query)).
EDIT: I can not write:
IF (a=='TABLE2) THEN queryA
ELSE IF (a=='TABLE3') THEN queryB
Since a is a field of TABLE1.
source
share