Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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.
declare @test table (data varchar(100))insert @testselect 'gm' union allselect '#gm' union allselect 'agm' union allselect '%t t gm' union allselect ' gm' union allselect '!gm' union allselect 'ogm' union allselect '_gm'select *,patindex('[^a-z]gm%', data )from @test