2009-03-03 119 views

回答

9
select case 
    when amount = 100 and date is not null then 'something' 
    else 'something else' 
    end 

这是一个 “被搜索的情况下的表达”(see MSDN):

CASE 
     WHEN Boolean_expression THEN result_expression [ ...n ] 
     [ ELSE else_result_expression ] END 
+0

打我2秒! – 2009-03-03 06:18:35

3
select someColumnName, 
     case 
     when amount = 100 AND someothercondition then 'XXX' 
     when amount = 1000 AND anothercondition then 'YYY' 
     else 'WWW' 
     end as "MyColumnName" 
from myTable 
0
select 
case 
    when 
     amount = 100 
     and date is not null  
    then 
     '0' 
    else 
     'something else' 
end 
-3

SELEC t case when amount = 100 and date is not null then'something'else'something when amount = 0 then'something else'end as MyColumnName