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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to use AND OR

Author  Topic 

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2009-02-18 : 16:22:46
I don't want to list a data if there is like '%XXX%' on fields _to or _from. And i need to list like '%AAA%' (both _to or _from fields)
select id, _from, _to from tblA
WHERE (_to like '%AAA%' Or _From like '%AAA%' OR _to NOT like '%XXX%' OR _from NOT like '%XXX%')

I mean i just need list where _to or _from not like '%AAA%' AND _to or _from like '%XXX%'

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-18 : 16:26:25
Perhaps this:
WHERE (_to like '%AAA%' Or _From like '%AAA%') AND (_to NOT like '%XXX%' OR _from NOT like '%XXX%')

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-18 : 16:27:13
Or maybe this:
WHERE (_to like '%AAA%' Or _From like '%AAA%') AND _to NOT like '%XXX%' AND _from NOT like '%XXX%'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-18 : 16:27:53
It's really hard to tell what you want with the information you provided. It is best to illustrate your issue with sample data and the exact expected output using that sample data that way we can clearly see the problem.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -