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
 Transact-SQL (2000)
 SELECT....CASE equivalent for SQL?

Author  Topic 

logjam
Starting Member

2 Posts

Posted - 2004-02-07 : 20:31:37
I need to know how I would do the SQL equivalent of a VBScript Select/Case block. I do know about the SQL command "CASE WHEN" but that only lets me define the value of a variable. I'm trying to do something like below:

SELECT CASE @storecode
CASE 1
INSERT INTO table1 ...
CASE 2
INSERT INTO table2 ...
CASE 3
.
.
.
END SELECT

How can I do this with SQL commands?

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-02-07 : 21:11:25
You have to do this with a bunch of IF statements. There isn't an equiviant of that style case/switch block on TSQL.


Damian
Go to Top of Page

logjam
Starting Member

2 Posts

Posted - 2004-02-07 : 21:42:04
Thanks for the reply. Is there anything proprietary to MS-SQL that could do this?
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-02-07 : 21:47:28
Nope.
You just have to write IF statements. TSQL is a better set language than it is for control of flow.


Damian
Go to Top of Page
   

- Advertisement -