How do I use T-SQL's Case/When?

后端 未结 4 528
广开言路
广开言路 2020-12-13 17:09

I have a huge query which uses case/when often. Now I have this SQL here, which does not work.

 (select case when xyz.something = 1
 then
     \'SOM         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 17:50

    As soon as a WHEN statement is true the break is implicit.

    You will have to concider which WHEN Expression is the most likely to happen. If you put that WHEN at the end of a long list of WHEN statements, your sql is likely to be slower. So put it up front as the first.

    More information here: break in case statement in T-SQL

提交回复
热议问题