Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 CASE or IF statement in where clause
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ArnoldG
Starting Member

Netherlands
36 Posts

Posted - 12/05/2013 :  09:56:27  Show Profile  Reply with Quote
Hello, I am struggling with this:
I want to conditionally filter in the WHERE clause.

When I would normally use WHERE, it would be:

WHERE [Brand]  = ‘_PARAM1_’


But I want to conditionally filter [Brand], OR have all the values of [Brand]

Something like:

(
IF 1=1 	
THEN [Brand] = '_PARAM1_' 
ELSE 'Give me all values' 
END
)


How do I properly translate that into a where clause ?
Thx,
Arnold

TG
Flowing Fount of Yak Knowledge

USA
6065 Posts

Posted - 12/05/2013 :  10:24:14  Show Profile  Reply with Quote
one way:
WHERE ([Brand] = '_PARAM1_' OR 1=1)
AND ...

Be One with the Optimizer
TG
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 12/05/2013 :  12:12:25  Show Profile  Reply with Quote
Perhaps you are trying to implement a "catch-all query?"

http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/
Go to Top of Page

ArnoldG
Starting Member

Netherlands
36 Posts

Posted - 12/05/2013 :  12:30:12  Show Profile  Reply with Quote
Thanks TG,
I did to get this kind of logic, but it works fine.

Also thank you Lamprey for your input. It explains a lot.

Arnold
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000