I have a long query with many tables in the FROM clause.
One of the tables has 100,000+ rows, which makes the whole query take a long time to run.
If a variable is set to TRUE, then that table is not needed at all in the FROM clause.
If the variable is set to FALSE, then a different variable is used to filter the table.
When I tried to add a case statement in the WHERE clause, it still took way too long to run!
I need help to conditionally add that table to the WHERE clause based on the variable being set.
In other words, if the variable is set to TRUE, I don't need that table at all, if the variable is set to FALSE, I need to add a statement to the WHERE clause.
See attached file.