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
 Query not excluding as expected

Author  Topic 

dibblejon
Starting Member

36 Posts

Posted - 2011-06-02 : 06:00:32
Hi

I have a query that I must of not got quite right! Basically when I run it I get records returning for "IDH" which I have tried to exclude. Could someone please help me?

SELECT customer.ACCOUNT, customer.NAME, customer.AREA, customer.SALESMAN, customer.CATEGORY, customer.PASSWORD, customer.EMAIL
FROM dbo.customer customer
WHERE (customer.AREA='8601') AND (customer.EMAIL Like '%@%') AND (customer.PASSWORD Not Like '%IDH%')
OR (customer.AREA='8601') AND (customer.EMAIL Like '%@%') AND (customer.PASSWORD Not Like '%PCT%')
OR (customer.AREA='8601') AND (customer.EMAIL Like '%@%') AND (customer.PASSWORD Not Like '%PHARM%')
ORDER BY customer.PASSWORD DESC

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2011-06-02 : 06:04:28
Bracket should be added like below -


SELECT customer.ACCOUNT, customer.NAME, customer.AREA, customer.SALESMAN, customer.CATEGORY, customer.PASSWORD, customer.EMAIL
FROM dbo.customer customer
WHERE (customer.AREA='8601' AND customer.EMAIL Like '%@%' AND customer.PASSWORD Not Like '%IDH%')
OR (customer.AREA='8601' AND customer.EMAIL Like '%@%' AND customer.PASSWORD Not Like '%PCT%')
OR (customer.AREA='8601' AND customer.EMAIL Like '%@%' AND customer.PASSWORD Not Like '%PHARM%')
ORDER BY customer.PASSWORD DESC


Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-06-02 : 06:07:57
SELECT customer.ACCOUNT, customer.NAME, customer.AREA, customer.SALESMAN, customer.CATEGORY, customer.PASSWORD, customer.EMAIL
FROM dbo.customer customer
WHERE customer.AREA='8601'
AND customer.EMAIL Like '%@%'
AND
(
customer.PASSWORD Not Like '%IDH%'
or customer.PASSWORD Not Like '%PCT%'
or customer.PASSWORD Not Like '%PHARM%'
)


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

dibblejon
Starting Member

36 Posts

Posted - 2011-06-02 : 07:20:17
Have run both these but I am still getting data returned where the string is IDH, PHARM etc.
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-06-02 : 07:38:40
I think you probably want

SELECT customer.ACCOUNT, customer.NAME, customer.AREA, customer.SALESMAN, customer.CATEGORY, customer.PASSWORD, customer.EMAIL
FROM dbo.customer customer
WHERE customer.AREA='8601'
AND customer.EMAIL Like '%@%'
AND customer.PASSWORD Not Like '%IDH%'
and customer.PASSWORD Not Like '%PCT%'
and customer.PASSWORD Not Like '%PHARM%'



==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

dibblejon
Starting Member

36 Posts

Posted - 2011-06-02 : 08:14:11
Awesome, thanks
Go to Top of Page
   

- Advertisement -