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
 General SQL Server Forums
 New to SQL Server Programming
 Multiple if in where clause

Author  Topic 

pliskin
Starting Member

3 Posts

Posted - 2011-04-21 : 01:20:44
Hi,

Another question from me.
How to query with many "if" in the where clause, like example below:


select * from table1 t1
where t1.a = 'text' and t1.b = 50 and
if @par = 0 then
t1.c = 1 and t1.z like '%text%'
else if @par = 1 then
t1.d = 1 and t1.z like '%text%'
else if @par = 2 then
t1.e = 1 and t1.z like '%text%'
end


Thanks.

X002548
Not Just a Number

15586 Posts

Posted - 2011-04-21 : 01:25:52
too tired

AND CASE WHEN t1.c = o THEN
CASE WHEN t1.c = 1


BUT What a mess you are coding



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -