Skip to content
Advertisement

How to set multiple values inside an if else statement?

I’m trying to SET more than one value within the if else statement below, If I set one value it works, but if I set two values, it doesn’t work:

Error message: “Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword ‘ELSE’.”

However it seems to be possible to have multiple SET variables after the else; this code works:

How can I do this correctly?

Advertisement

Answer

If you have more than one statement in a if condition, you must use the BEGIN ... END block to encapsulate them.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement