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

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

hbadministrator
Posting Yak Master

118 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.

Table
Equipment
fields
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.

Ifor
Aged Yak Warrior

585 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

hbadministrator
Posting Yak Master

118 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  
 New 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.05 seconds. Powered By: Snitz Forums 2000