SQL Server Developer >> Join IF...
Typically the purpose of a JOIN is to return columns from more than one
table. Do you mean you want to bring back a different set of columns
depending on input? If so, then use an IF statement. Avoid using SELECT
* in production code because it creates a lot of problems for
maintenance and reliability.
BEGIN
SELECT ...
FROM Table1
WHERE active = 1
END
ELSE
BEGIN
SELECT ...
FROM Table1
JOIN ...
WHERE active = 1
END
Alternatively, if the columns to be returned are the same in each case
you can just add the parameter to the ON clause: