Removing Special Characters like @,=,$,<> etc. from String using Stuff and PatIndex function.

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 864
DECLARE @regex INT,@string_val varchar(100);
SET @string_val = 'welcome-to''dotnet=funda@dot.com#$';
SET @regex = PATINDEX('%[^a-zA-Z0-9 ]%', @string_val);
WHILE @regex > 0
BEGIN
SET @string_val = STUFF(@string_val, @regex, 1, ' ' )
SET @regex = PATINDEX('%[^a-zA-Z0-9 ]%', @string_val)
END
SELECT @string_val;

Output:-
welcome to dotnet funda dot com

Comments or Responses

Login to post response