Randall Fox wrote:

What does the first expr do in a CASE expression ?

I understand the rest of the syntax, but I don't get what the very
first expr (after the keyword "case") does..  And I couldn't find the
answer in the documentation or wiki..

Thanks

Randall Fox


There's a few ways you can use case statements, I think you're referring to this:

select
   case field1
      when 1 then
            field1+1
      when 2 then
            field1/2
      else
            1
   end as casefield
   from table1;

in which case, field1 will be compared to each "when value" to determine which "then value" to return. It's very similar to a switch statement.

Case can also be used as an if elseif else type statement, when the field is omitted.


select case when field1 is null then field2 else field1 end as casefield from table1;


John LeSueur

Reply via email to