Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB style Select Case in a Stored Proc?

Status
Not open for further replies.

joebickley

Programmer
Aug 28, 2001
139
0
0
GB
Hi in VB a select case is

select x
case a
do this
case b
do this
end select

but how do i do this in a proc? I can only find how to do it in a select statement and this is not what i want to do.
Thanks

Joe

 
"if" is the control of flow statement

select @x = x

if @x = '1'
begin
do this
end
else if @x = '2'
begin
do this
end
else if @x = '3'
begin
do this
end


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Not that was a fast reply, 2 mins!!

although i know how to do "ifs" in this way but case statements are far tidier if they are supported.



 
Unfortunately SELECT CASE is not supported in TSQL.

--James
 
You can use a select case statment see example:

SELECT au_fname, au_lname,

CASE state
WHEN 'CA' THEN 'California'
WHEN 'KS' THEN 'Kansas'
WHEN 'TN' THEN 'Tennessee'
WHEN 'OR' THEN 'Oregon'
WHEN 'MI' THEN 'Michigan'
WHEN 'IN' THEN 'Indiana'
WHEN 'MD' THEN 'Maryland'
WHEN 'UT' THEN 'Utah'
END AS StateName

FROM pubs.dbo.authors
ORDER BY au_lname

 
As i said in the original post, i know you can do it in a select statement but i dont wont to return a set of data its just the decision tree i wanted. JamesLean is right they are not supported

I just asked in case i had missed something and someone new better

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top