Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Slick way to remove special char
Message
From
26/03/2008 09:53:36
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Slick way to remove special char
Miscellaneous
Thread ID:
01305645
Message ID:
01305645
Views:
49
I have a sp to remove special characters from an input string, and it works fine, but I am wondering if there is a slicker (is that a word?) way to do this. The code is:
ALTER PROCEDURE [dbo].[sRemoveSCW]
@StringIn VARCHAR(2000),
@StringOut VARCHAR(2000) OUTPUT
AS
BEGIN
	SET NOCOUNT ON;

	SET @StringOut = REPLACE(@StringIn, '~', '')
	SET @StringOut = REPLACE(@StringOut, '`', '')
	SET @StringOut = REPLACE(@StringOut, '!', '')
	SET @StringOut = REPLACE(@StringOut, '@', '')
	SET @StringOut = REPLACE(@StringOut, '#', '')
	SET @StringOut = REPLACE(@StringOut, '$', '')
	SET @StringOut = REPLACE(@StringOut, '%', '')
	SET @StringOut = REPLACE(@StringOut, '^', '')
	SET @StringOut = REPLACE(@StringOut, '&', '')
	SET @StringOut = REPLACE(@StringOut, '*', '')
	SET @StringOut = REPLACE(@StringOut, '(', '')
	SET @StringOut = REPLACE(@StringOut, ')', '')
	SET @StringOut = REPLACE(@StringOut, '+', '')
	SET @StringOut = REPLACE(@StringOut, '=', '')
	SET @StringOut = REPLACE(@StringOut, '{', '')
	SET @StringOut = REPLACE(@StringOut, '}', '')
	SET @StringOut = REPLACE(@StringOut, '[', '')
	SET @StringOut = REPLACE(@StringOut, ']', '')
	SET @StringOut = REPLACE(@StringOut, '|', '')
	SET @StringOut = REPLACE(@StringOut, ';', '')
	SET @StringOut = REPLACE(@StringOut, ':', '')
	SET @StringOut = REPLACE(@StringOut, '<', '')
	SET @StringOut = REPLACE(@StringOut, '>', '')
	SET @StringOut = REPLACE(@StringOut, '?', '')
	SET @StringOut = REPLACE(@StringOut, ',', '')
	SET @StringOut = REPLACE(@StringOut, ' ', '')
	SET @StringOut = REPLACE(@StringOut, '/', '')
	SET @StringOut = REPLACE(@StringOut, '\', '')
	SELECT @StringOut
END
Any input or comments are appreciated!
Thank You

Rollin Burr

Politicians and diapers have one thing in common. They should both be changed regularly, and for the same reason.
Next
Reply
Map
View

Click here to load this message in the networking platform