Talk, guys!
Would anyone know how I can use a UNION ALL conditionally?
Example:
DECLARE @cond INT = 1
SELECT * FROM table1
IF(@cond = 1)
BEGIN
UNION ALL
SELECT * FROM table2
END
The idea is this but this does not work. How could I join the table only if the condition was true?
It needs to be in this context because I have several tables that will be chosen by the user, so it could be: t1, t1 + t2, t1 + t2 + t3, t1 + t3, t2 + t3 + t5, ...