Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Question about the CASE statement
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00716871
Message ID:
00716912
Views:
16
>Can I set a variable within the CASE statement? I keep getting a syntax error when trying to set a variable within a CASE statement. I need to set a variable at the row level.

Probably the reason that you're having an issues is that CASE is an expression.

SET @var = CASE WHEN 1 THEN 'a' WHEN 2 THEN 'b' ELSE 'c' END

-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Reply
Map
View

Click here to load this message in the networking platform