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 ?
Effectively an else-if; The
CASEstatement will return the 1st matching value, so whenagentid=@agentidis satisfied evaluations stops without examining the otherWHENconditions & 4 will be returned.