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
 Matching Multiple conditions in where clause

Author  Topic 

cmor
Starting Member

2 Posts

Posted - 2012-08-06 : 18:24:31
I'm looking through specific stlyes in retail data, here's my where clause:


and (a.style_id = 0004
Or a.style_id = 5132
Or a.style_id = 0029
Or a.style_id = 1521
Or a.style_id = 2084
Or a.style_id = 5134
Or a.style_id = 5135)
and (a.style_id != 0004 and a.color_id != 50)


I'm looking at specific styles, and want to exclude one style color combo. The above excludes all styles with color 50. I want just style 0004 with color 50 excluded. It sounds like a very simple answer, I'm just not seeing it. Thanks, - Chris

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-06 : 18:27:43
just make it like


(a.color_id = '0004' and a.color_id != 50)
OR a.style_id in ('5132','0029','1521','2084','5134','5135')


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

cmor
Starting Member

2 Posts

Posted - 2012-08-06 : 19:34:20
Thank you. That is an overall better way to do it.

-Chris
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-07 : 09:48:13
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -