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
If you are using a parameter, then you only need one statement.
@ID (Some parameter) ;with CTE ( select * from table_A WHERE id = @ID union all select * from table_B WHERE (id = @ID and condition) )