I want to execute select statement within CTE based on a codition. something like below
;with CTE_AorB ( if(condition) select * from table_A else
I think the IF ELSE stuff might have poor caching if your branch condition flips. Maybe someone more knowledgeable can comment.
Another way would be to UNION ALL with the WHERE clauses as suggested by others. The UNION ALL would replace the IF ELSE