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 |
|
Exir
Posting Yak Master
151 Posts |
Posted - 2009-02-09 : 06:04:17
|
| How can i have something like this:SELECT CASE WHEN @a='condition1' THEN (select * from request where id=1) WHEN @a='condition2' THEN ( select * from requestcondition where name='something') END I want to hav edifferent selects depends on the content of @a |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-09 : 06:10:02
|
you need to use IF insteadIF @a='condition1' select * from request where id=1 IF @a='condition2' select * from requestcondition where name='something' |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-02-09 : 06:10:40
|
| sub queries dont allowed in case statement |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-02-09 : 06:12:32
|
| Try Like thisdeclare @a int,@str varchar(255)select @str = ''select @a = 1select @str = 'select * from emptable' where @a= 1 select @str ='select * from oas_pms.dbo.tbl_pms_projects' where @a = 2exec(@str)Jai Krishna |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-09 : 06:15:10
|
| why dynamic sql? |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-02-09 : 06:15:25
|
| sub queries are allowed in case statement but need to return only one column valueJai Krishna |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-02-09 : 09:08:32
|
quote: Originally posted by Jai Krishna sub queries are allowed in case statement but need to return only one column valueJai Krishna
There is no sub-query in Visakh's code. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-02-09 : 09:18:14
|
| Visakh's code is effecient to useMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-09 : 09:39:52
|
quote: Originally posted by madhivanan Visakh's code is effecient to useMadhivananFailing to plan is Planning to fail
wow...finally Madhi is back! |
 |
|
|
|
|
|