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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 stored procedures and case statment

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-01-23 : 09:25:00
i am writing a stored procedure which uses case statment (not as a part of a select) and i want the result to put into a @val1
how do i do that?
thnaks i advance
peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-23 : 09:34:03
case statment (not as a part of a select)
What do you mean by that?


Select @val1 = Case When SomeCodition1 Then someValue1
When SomeCondition2 Then someValue2
...
End
From SomeTable


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2007-01-23 : 09:35:00
[code]
SELECT @val1 = CASE
WHEN [FirstCondition]
THEN [FirstValue]
WHEN [SecondCondition]
THEN [SecondValue]
... etc...
ELSE [ElseValue]
END[/code]
Clearly, as this isn't inline, you could use IF/ELSEIF.

Mark
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-01-23 : 10:12:26
thnaks mwjdavidson
thaty what i wanted
btw : i didnt see elsei code
Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2007-01-23 : 12:26:26
No problem. Lookup "IF...ELSE" in BOL.

Mark
Go to Top of Page
   

- Advertisement -