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
 Development Tools
 Other Development Tools
 using if else clause in where clause

Author  Topic 

mahesh423
Starting Member

9 Posts

Posted - 2008-09-30 : 09:21:22
Hi
i have a select query which actually differs depending upon the input parameters passed to the stored proc.
i will pass a flag parameter which will have values either 1 or 0.
the query is
select 1,2,3,4
from A
where A.state in (open,pending,waiting)
if flag = 0
the query must remain same
if flag =1
then
an additional state must get included i.e (settled)
select 1,2,3,4
from A
where A.state in (open,pending,waiting.settled)
i am thinkin a conditional stmt must work out...
plz suggest me a better and efficient way to implement this..





Mahesh Kumar

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-30 : 09:23:05
Are you using Sybase?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=111591



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-30 : 09:25:06
[code]SELECT 1,
2,
3,
4
FROM a
WHERE a.State IN ('open', 'pending', 'waiting')
OR (@Flag = 1 AND a.State = 'settled')[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

mahesh423
Starting Member

9 Posts

Posted - 2008-09-30 : 22:28:09
Hi
thanks for that smart query..tat will help me alot..


Mahesh Kumar
Go to Top of Page
   

- Advertisement -