if else within CTE?

前端 未结 4 2132
孤独总比滥情好
孤独总比滥情好 2021-01-02 07:51

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
           


        
4条回答
  •  独厮守ぢ
    2021-01-02 08:12

    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

提交回复
热议问题