Reputation: 999
Does the case statement work like "if - else if" or like "if - if"?
Let's say, I write
...ORDER BY CASE WHEN agentid=@agentid THEN 4 WHEN status='GOLD' THEN 3 WHEN status='SILVER' THEN 2 WHEN status='BASIC' THEN 1 END DESC
Will an entry where the agentid is @agentid and the status is GOLD be 7 or 4 ?
Upvotes: 0
Views: 35
Reputation: 175916
Effectively an else-if; The CASE
statement will return the 1st matching value, so when agentid=@agentid
is satisfied evaluations stops without examining the other WHEN
conditions & 4 will be returned.
Upvotes: 1