471,092 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

Replace function and regular expressions

Is it possible to use the REPLACE function in SQL Server 2000 so that
it returns a string containing only alpha-numeric characters (much
like using regular expressions)?

Thank you in advance for any suggestion.

Darren.
Jul 20 '05 #1
1 3688
I think you'll have to do it iteratively:

CREATE FUNCTION dbo.CleanChars
(@str VARCHAR(8000), @validchars VARCHAR(8000))
RETURNS VARCHAR(8000)
BEGIN
WHILE PATINDEX('%[^' + @validchars + ']%',@str) > 0
SET @str=REPLACE(@str, SUBSTRING(@str ,PATINDEX('%[^'
+ @validchars +']%',@str), 1) ,'')
RETURN @str
END

GO

SELECT dbo.CleanChars('TESTING1234','0-9')

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by higabe | last post: by
24 posts views Thread by Wim Roffal | last post: by
18 posts views Thread by Jon S via DotNetMonster.com | last post: by
9 posts views Thread by Whitless | last post: by
4 posts views Thread by jgabbai | last post: by
3 posts views Thread by Roy W. Andersen | last post: by
11 posts views Thread by Fabri | last post: by
1 post views Thread by NvrBst | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.