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)
 Non-alphanumeric position in string

Author  Topic 

sanjnep
Posting Yak Master

191 Posts

Posted - 2008-12-01 : 14:13:28
I am trying to find the position of non-alphanumeric position except the character + or ; or ( or ) for the triming purpose. I can do for all non-alphanumeric position from following code but how can I escape when the character is + OR ; OR ) OR ( ?
Thanks
Sanjeev
_____________________________________________

declare @str varchar(100)
select @str = 'san&%()v;+;'
select PATINDEX('%[^a-z0-9 _]%',@str)

Sanjeev Shrestha
12/17/1971

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-12-01 : 15:53:16
Sorry, I don't understand what you want when you say "how can I escape".

Maybe:

declare @str varchar(100)
select @str = 'san&%()v;+;'
select PATINDEX('%[^a-z0-9 _]%',@str)

this:
select left(@str,(PATINDEX('%[^a-z0-9 _]%',@str))-1)

or this:
select substring(@str,0,(PATINDEX('%[^a-z0-9 _]%',@str)))

and I have not considered if there is a string without any character for patindex to find...
Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -