Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
newbie22
Starting Member
2 Posts |
Posted - 2012-02-02 : 16:13:13
|
| Hello all,I am trying to create a case expression with if else nested in it.Here is what i am tryin to do-------Crerate Sp_testASBEGINDECLARE @var1,var2,var3SELECT @var1= ColName FROM Control Where 1=1Select Case (@var1)WHEN 0 then if(var2!=var3) Begin { Statements } End ELSE Statement Else Statement ENDENDGo-----------I apologize for such a silly question but i am a total neewbie ...The error i am getting is Error 0:Syntax error or access violation |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-02 : 18:19:33
|
| if you want is to vary result set based on condition then you need to use IF ..ELSE and write seperate select statements with each. If you just want to return value based on condition you need to use CASE ...WHEN within select statement just like you've it now------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
newbie22
Starting Member
2 Posts |
Posted - 2012-02-03 : 08:06:21
|
| Thank you everyone.. got it figured out.. you were correct, i just used IF ELSE and got what i wanted. Thank you so much |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-03 : 09:17:25
|
| ok..glad that you got what you wanted------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|