|
Hello Everyone, I am a beginner trying to learn T-SQL and here is where I was stuck. Can anyone please help me out with this. use AdventureWorks go declare @n as int =1 n = CASE when n=1 then print('n=1') when n=2 then print ('n=2') print ('that implies n>1') when n=2+2 then print('n=4') else print('n is some other value.') end Thankyou very much.....It would be of great help !!
(comments are locked)
|
|
You can't mix assignment with output in CASE statement. You can print the output basing on the value of the @n variable using following syntax for example:
Please note that each time you use variable it must be prefixed with @ and print statement contains conditional expression that determines what has to be printed. Alternatively, you can assign the output of case statement to a variable and print it:
When you assign a value to a variable, you have to use keyword Regards Piotr
(comments are locked)
|
|
you should be using IF . . ELSE for flow control not CASE .. WHEN CASE .. WHEN is to use within a QUERY Thankyou so much guys... It was really helpful !!
May 24 '10 at 11:13 AM
pragathi
(comments are locked)
|

