在TSQL中用case,when之类同时查多种情况

 

 

有时发现在写T-SQL  中可以用

case ...

when

then

end

这一组语句后,

可以比较大程度上去除用union后的语句膨胀.

 

WHERE


case
when m.object_type_id in(2, 11) then ( m.object_id)
else ( m.station_id) end
= 225683000

 

注意.

如果写成

case 
when m.object_type_id in(2, 11) then ( m.object_id)
else ( m.station_id) end
= 225683000

这样还是会

case 
when m.object_type_id in(2, 11) then ( m.object_id = 225683000)
else ( m.station_id = 225683000) end
还是不会通过的

posted on 2012-08-21 11:25  Orz..  阅读(462)  评论(0编辑  收藏  举报

导航