Link to home
Start Free TrialLog in
Avatar of SNilsson
SNilssonFlag for Sweden

asked on

Case statement T-SQL syntax


This works:
SET @X = Case @Y
          WHEN 1 THEN 444
          WHEN 2 THEN 555
END


How can I make this work:
Case @Y
    WHEN 1 THEN
          SET @X =  444
          SET @Z =  222
    WHEN 2 THEN
          SET @X =  555
          SET @Z =  333
END
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SNilsson

ASKER


Okey, in that case what would be the most efficient, using several If statement or two case statements (Y can hold 7 different valuse so it would be 7 IF's) ?
SNilsson,

50/50 I guess, either way you have 14 sets to do, probably the IFs would be easier to read and maintain.

Tim.