CREATE FUNCTION dbo.UDF_ParseAlphaNumChars
(
@string VARCHAR(8000)
)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @IncorrectCharLoc SMALLINT
SET @IncorrectCharLoc = PATINDEX('%[^0-9A-Za-z]%', @string)
WHILE @IncorrectCharLoc > 0
BEGIN
SET @string = STUFF(@string, @IncorrectCharLoc, 1, '')
SET @IncorrectCharLoc = PATINDEX('%[^0-9A-Za-z]%', @string)
END
SET @string = LTRIM(RTRIM(REPLACE(@string,' ','')))
RETURN @string
END
GO
—-Test
SELECT dbo.UDF_ParseAlphaNumChars('ABC”_I+{D[]}4|:e;””5,<.F>/?6')
GO
This entry was posted
on Tuesday, May 26, 2009
and is filed under
SQL Server
.
You can leave a response
and follow any responses to this entry through the
Subscribe to:
Post Comments (Atom)
.
0 comments