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 2000 Forums
 Transact-SQL (2000)
 Can I do this....Not Like bla%.

Author  Topic 

ASP_DRUG_DEALER
Yak Posting Veteran

61 Posts

Posted - 2004-07-14 : 15:48:15
Hey all-
I need to do a query and get all "Overhead" crap for a report, but there is no good way of doing this besides telling it what not to include (to many open-ended fields. It needs to be for a certian job\project

I can get one NOT LIKE BLA% but any more then that it does not work.

SELECT E_NUM, E_ID, EO_ACCOUNT, EO_DEPT, EO_YEARMONTH, EO_UNITS, EO_DOLLARS, EO_C_ID, EO_B_ID, EO_O_ID, ER_C_ID, ER_B_ID, ER_O_ID, ER_CHANGE
FROM E_MASTER

WHERE
(((ER_ACCOUNT NOT LIKE '501%') OR
(ER_ACCOUNT NOT LIKE '509%') OR
(ER_ACCOUNT NOT LIKE 'PROV%'))
AND
ER_J_ID = 'A0001')

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-07-14 : 15:50:55
if it is '501ksajgf' then the where condition evals to

(false or true or true) and false


looks like you got your ands and ors backwards


try:
WHERE
(((ER_ACCOUNT NOT LIKE '501%') AND
(ER_ACCOUNT NOT LIKE '509%') AND
(ER_ACCOUNT NOT LIKE 'PROV%'))
OR
ER_J_ID = 'A0001')


Corey
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-07-14 : 15:59:35
remember: if A,B,C are boolean expressions, the opposite of

A and B and C

is

(Not A) or (Not B) or (Not C)


- Jeff
Go to Top of Page

ASP_DRUG_DEALER
Yak Posting Veteran

61 Posts

Posted - 2004-07-14 : 16:12:00
whoa!
Hang on just a second....

So in my case if I wanted.

(((ER_ACCOUNT LIKE '501%') OR
(ER_ACCOUNT LIKE '509%') OR
(ER_ACCOUNT LIKE 'PROV%'))
AND
ER_J_ID = 'A0001')

But since I want the inverse for all but the ER_J_ID, I would do this..
(((ER_ACCOUNT NOT LIKE '501%') AND
(ER_ACCOUNT NOT LIKE '509%') AND
(ER_ACCOUNT LIKE 'PROV%'))
AND
ER_J_ID = 'A0001')

is this correct?
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-07-14 : 16:19:55
i believe you are correct -- that should work.

- Jeff
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-07-14 : 23:45:19
With your second example you don't need all the (((((()))))) AND is inclusive. Or is exclusive.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -