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 need to strip out all non letter/number characters from a series of strings in a query. Is there a better way to do this than a bunch of replace functions?
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts
Posted - 2005-10-20 : 12:57:40
[code] /********************************* Removes any characters from @myString that do not meet the provided criteria. *********************************/ CREATE FUNCTION dbo.GetCharacters(@myString varchar(500), @validChars varchar(100)) RETURNS varchar(500) AS BEGIN
While @myString like '%[^' + @validChars + ']%' Select @myString = replace(@myString,substring(@myString,patindex('%[^' + @validChars + ']%',@myString),1),'')
Return @myString END Go
Declare @testStr varchar(1000), @i int
Set @i = 1 while @i < 255 Select @TestStr = isnull(@TestStr,'') + isnull(char(@i),''), @i = @i + 1