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)
 LIKE %[^abc]

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2007-02-21 : 09:11:29
I'm sure this can't be done, please prove me wrong...

I've got a select ... WHERE column LIKE @parameter

is there a value of @parameter that would find all columns NOT ending with, or containing, a specific string, e.g. %abc% ?

We would like to not rewrite the LIKE condition to be NOT LIKE.

Sam

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-21 : 09:16:37
LIKE '%[^a-z]'

is the same as

not like '%[a-z]'


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-02-21 : 11:00:46
"Ending with" you could do

select ... WHERE column LIKE '%[^a][^b][^c]'

but it won't match rows with [column] length < 3

No way to do it for a "containing", unless its a Single Character, or RegEx in SQL 2005 is beefier than SQL 2000

Kristen
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2007-02-22 : 08:50:50
quote:
Originally posted by Kristen

No way to do it for a "containing", unless its a Single Character, or RegEx in SQL 2005 is beefier than SQL 2000

This is 2005. Is RegEx part of the LIKE comparison?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-02-22 : 09:10:30
Sorry, I don't know for SQL 2005.

I would be very interested to know if BoL suggest that LIKE is "beefier" than in SQL 2000 ?

Kristen
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-02-22 : 10:51:08
no it's not.
you can use CLR for regex.

Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -