Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have 2 tables one that contains 3 searches that don't work correctly.TableEquipmentfields Model, active, DeliveryStatus, prod-typeThe 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
700 Posts
Posted - 2014-08-22 : 11:09:37
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')