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)
 String matching woes

Author  Topic 

Debbie2
Starting Member

11 Posts

Posted - 2006-09-20 : 04:27:05
I have this code:

or @charname LIKE 'GM%'
or @charname LIKE '[^a-z]GM%'
or @charname LIKE '[^a-z][^a-z]GM%'
or @charname LIKE '[^a-z][^a-z][^a-z]GM%'
or @charname LIKE '[^a-z][^a-z][^a-z][^a-z]GM%'

Is there a cleaner way of writing that? If MSSQL supported true regexps I'd be able to write:

or @charname LIKE '[^a-z]+GM%'

Basically I want to test whether the string starts with "GM", not counting non-alphabetical characters.

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-09-20 : 04:35:16
have a look at the following links
http://www.4guysfromrolla.com/webtech/regularexpressions.shtml
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=27205&SearchTerms=expressions
http://blogs.msdn.com/khen1234/archive/2005/05/11/416392.aspx

Chirag
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-20 : 05:00:33
Here is a test
declare @test table (data varchar(100))

insert @test
select 'gm' union all
select '#gm' union all
select 'agm' union all
select '%t t gm' union all
select ' gm' union all
select '!gm' union all
select 'ogm' union all
select '_gm'

select *,
patindex('[^a-z]gm%', data )
from @test


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -