Please start any new threads on our new site at 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!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Simple nested question
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

120 Posts

Posted - 08/22/2014 :  10:39:30  Show Profile  Reply with Quote
I have 2 tables one that contains 3 searches that don't work correctly.

Model, active, DeliveryStatus, prod-type

The where statement is
Where active = 'A' and Model = 'FOTNK' OR Model = 'LPTNK'

The results actually show all the FO and LP tanks so thats good but it pulls all active 'A''s but also some 'I' as well. My thought is I should do a select with a where on Active first then a select for the FOTNK and LPTNK or the other way around. I just don't know how to write it. Any help is greatly appreciated.

Aged Yak Warrior

700 Posts

Posted - 08/22/2014 :  11:09:37  Show Profile  Reply with Quote
AND has a higher order of precedence than OR so your current WHERE clause can be written as

WHERE (active = 'A' AND Model = 'FOTNK') OR Model = 'LPTNK'

I suspect you want:

WHERE active = 'A' AND (Model = 'FOTNK' OR Model = 'LPTNK')

which reduces to:

WHERE active = 'A' AND Model IN ('FOTNK', 'LPTNK')

Go to Top of Page

Posting Yak Master

120 Posts

Posted - 08/22/2014 :  11:33:17  Show Profile  Reply with Quote
bingo! Thank you
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.03 seconds. Powered By: Snitz Forums 2000