2011-08-09 48 views
1

如何按大小寫篩選?T-Sql如何按大小寫篩選

select * from address 
where streetnum > 1000 only when state = MI otherwise select everything else 

select * from address 
where case when state = MI then streetnum > 1000 
+0

仇敵會討厭LOL –

回答

2

如果我理解你的問題正確,然後...

select * from address 
where state <> 'MI' or (state = 'MI' and streetnum > 1000) 
2

address,獲取所有行,但是當state'MI'然後streetnum必須比1000更大。

select * from address 
where streetnum > 1000 or state <> 'MI' 

如果你想使用case你可能有多個值來檢查。

select * 
from address 
where case state 
     when 'MI' then 1000 
     when 'MA' then 1000 
     else 0 
     end < streetnum 

而且,如果您對所有狀態具有相同的值(1000),那麼這將與此相同。

select * 
from address 
where streetnum > 1000 or state not in ('MI', 'MA') 
+0

加上一個正確解釋的問題。 –