June 2, 2015 at 12:44 pm
Good afternoon!
Can anyone assist me in converting this to a case statement?
IF (@Variable NOT IN ('here', 'or here'))
BEGIN
SELECT @errorMsg = 'message here'
GOTO ERROR
END
¤ §unshine ¤
June 2, 2015 at 12:55 pm
What exactly are you trying to convert to a case statement? You wouldn't put a goto or any control flow for that matter in a case statement.
June 2, 2015 at 1:08 pm
Ok. Thank you.
I was trying to change the IF to a CASE.
CASE WHEN @Variable IN ().
Thanks again!
¤ §unshine ¤
June 2, 2015 at 3:59 pm
In MS SQL Server the CASE is not used for flow control. Your original post shows that you are attempting to control the flow of execution. What are you trying to accomplish by using CASE?
June 3, 2015 at 12:09 am
hi sunshine i hope this case statement work
CASE
WHEN (@Variable NOT IN ('here', 'or here'))
THEN
SELECT @errorMsg = 'message here'
ELSE GOTO ERROR
END
June 3, 2015 at 2:52 am
nagraj275 (6/3/2015)
hi sunshine i hope this case statement work
It won't, because as Lynn said above, CASE is not used for control flow in SQL Server.
If you'd tried to parse the code you wrote, it would be abundantly clear that it won't work
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 3, 2015 at 2:53 am
sunshine-587009 (6/2/2015)
Ok. Thank you.I was trying to change the IF to a CASE.
CASE WHEN @Variable IN ().
IF and CASE are not interchangeable. IF is used for control flow. Case is an expression used within a statement.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 3, 2015 at 6:39 am
Ok. Thank you so much for your help! 🙂
¤ §unshine ¤
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply