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.
| Author |
Topic |
|
dibblejon
Starting Member
36 Posts |
Posted - 2011-06-02 : 06:00:32
|
HiI 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.EMAILFROM dbo.customer customerWHERE (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.EMAILFROM dbo.customer customerWHERE (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 TIf I cant go back, I want to go fast... |
 |
|
|
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.EMAILFROM dbo.customer customerWHERE 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. |
 |
|
|
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. |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-02 : 07:38:40
|
| I think you probably wantSELECT customer.ACCOUNT, customer.NAME, customer.AREA, customer.SALESMAN, customer.CATEGORY, customer.PASSWORD, customer.EMAILFROM dbo.customer customerWHERE 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. |
 |
|
|
dibblejon
Starting Member
36 Posts |
Posted - 2011-06-02 : 08:14:11
|
| Awesome, thanks |
 |
|
|
|
|
|
|
|