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
 SQL Server Development (2000)
 wild card

Author  Topic 

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2005-03-24 : 10:33:15
CREATE TABLE tt (data varchar(10))

INSERT tt
SELECT 'aaaa'
UNION
SELECT 'bbbb'
UNION
SELECT 'cccc'
UNION
SELECT 'dddd'

SELECT data
FROM tt
WHERE data NOT IN ('a%','b%')

The above query is not returning the expected output. It is returning 4 records. I am expecting 2. How can i modify the query?



------------------------
I think, therefore I am

PW
Yak Posting Veteran

95 Posts

Posted - 2005-03-24 : 10:37:01
NOT LIKE instead of NOT IN
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-03-24 : 10:37:05
EDIT: Damn, 4 seconds

SELECT data
FROM tt
WHERE data NOT LIKE 'a%'
AND data NOT LIKE 'b%'


Brett

8-)
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2005-03-24 : 10:46:13
I know that will work. But i have a long list to be put in the filter. The approach you have suggested may not be efficient, i will use that if there is no alternative...


------------------------
I think, therefore I am
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2005-03-24 : 10:53:42
Got it.

SELECT data
FROM tt
WHERE data NOT LIKE '[ab]%'


------------------------
I think, therefore I am
Go to Top of Page

PW
Yak Posting Veteran

95 Posts

Posted - 2005-03-24 : 10:58:53
>>The approach you have suggested may not be efficient,

Uhh, I didn't suggest it, you did in your original post. If you'd posted that your problem was efficiency in *addition* to incorrect results ...

>>i will use that if there is no alternative...

There are alternatives.
Go to Top of Page
   

- Advertisement -