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 problem

Author  Topic 

crosurfer
Starting Member

2 Posts

Posted - 2008-05-09 : 07:38:01
Hi,
Im trying to put a select statement into select case.

Something like this:

select case  @type

when 'A' then (select * from table1)
when 'B' then (select * from table2)
when 'C' then (select * from table3)
end


But i get this error: Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

Is it possible to do this?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-09 : 07:43:23
IF @Type = 'A'
SELECT * FROM Table1

IF @Type = 'B'
SELECT * FROM Table2

IF @Type = 'C'
SELECT * FROM Table3



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-05-09 : 07:43:32
Use IF or if your table structures are similar then use UNION ALL.



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

crosurfer
Starting Member

2 Posts

Posted - 2008-05-09 : 08:10:16
quote:
Originally posted by Peso

IF @Type = 'A'
SELECT * FROM Table1

IF @Type = 'B'
SELECT * FROM Table2

IF @Type = 'C'
SELECT * FROM Table3



E 12°55'05.25"
N 56°04'39.16"




Thank you.
Go to Top of Page
   

- Advertisement -