tags:

views:

547

answers:

4

I want to do a case on the result of 2 columns. How do I do this?

e.g.:

SELECT CASE amount=100 AND DATE IS NOT NULL WHEN 0 THEN 'Something' ELSE ''

Something like that?

+3  A: 
select case
    when amount = 100 and date is not null then 'something'
    else 'something else'
    end

This is a "searched case expression" (see MSDN):

    CASE
      WHEN Boolean_expression THEN result_expression [ ...n ] 
      [ ELSE else_result_expression ]  END
Marc Gravell
beat me by 2 seconds!
Mitch Wheat
+2  A: 
select someColumnName,
       case 
         when amount = 100  AND someothercondition then 'XXX'
         when amount = 1000  AND anothercondition then 'YYY'
         else 'WWW' 
       end as "MyColumnName"
from myTable
Mitch Wheat
A: 

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

Mufaka
A: 

Look for SELECT WHEN

http://www.4guysfromrolla.com/webtech/102704-1.shtml

shahkalpesh