Various I.T. gems found on my travels
SQL Function to Replace Many Characters
The following function will return a string devoid of the supplied characters in the second parameter:
USAGE:
SELECT dbo.fnStringReplace(‘MyTestString-*&@’, ‘&@-*’)
FUNCTION:
/*
Purpose:
Returns a string devoid of the given characters.
Type:
Scalar Return
Prototype:
Print dbo.fwt_StringReduce(‘Bob Herguth@#$^&*()’, ‘@#$^&*()’)
*/
CREATE FUNCTION fwt_StringReduce
(
@inputstr VARCHAR(4096)
, @stripchrs VARCHAR(255)
)
RETURNS VARCHAR(4096)
AS
BEGIN
DECLARE @charcounter INT
SET @charcounter = 1
WHILE @charcounter <= LEN(@stripchrs)
BEGIN
SET @inputstr = REPLACE(@inputstr, SUBSTRING(@stripchrs, @charcounter, 1), ”)
SET @charcounter = @charcounter + 1
END
RETURN @inputstr
END
Steve Lugovsky, singing out
| Print article | This entry was posted by admin on July 27, 2010 at 9:05 am, and is filed under MySQL, SQL, SQL Server. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |