CASE expressions can be used in SQL anywhere an
expression can be used. Example of where CASE expressions can be used include
in the SELECT list, WHERE clauses, HAVING clauses, IN lists, DELETE and UPDATE
statements, and inside of built-in functions.
Syntax:
CASE expressionWHEN expression1 THEN expression1[[WHEN expression2 THEN expression2] [...]][ELSE expressionN]ENDExample:DECLARE @Test INTSET @Test
= 3SELECTCASE @TestWHEN 1 THEN 'First'WHEN 2 THEN 'Second'WHEN 3 THEN 'Third'ELSE 'Other'END
No comments:
Post a Comment