Introduction:
Here I will explain how to remove special characters from string in sql server 2008 with spaces or sql server replace special characters in string with spaces in sql server 2008 or replace unwanted characters in string in sql server.
Here I will explain how to remove special characters from string in sql server 2008 with spaces or sql server replace special characters in string with spaces in sql server 2008 or replace unwanted characters in string in sql server.
Description:
In
previous articles I explained replace multiple spaces with single space in sql, reseed identity column value in sql server, get time difference between two dates
in sql,
substring function in SQL server
and many articles relating to SQL
server.
Now I will explain how to remove special characters from string with spaces in sql
server 2008.
To
replace special characters from string with spaces in sql
server we
need to write the query like this
DECLARE @regex INT,@string varchar(100)
SET @string='welcome-to''aspdotnet=sures@h.com#$'
SET @regex = PATINDEX('%[^a-zA-Z0-9 ]%',
@string)
WHILE @regex >
0
BEGIN
SET @string = STUFF(@string, @regex, 1, ' ' )
SET @regex = PATINDEX('%[^a-zA-Z0-9 ]%',
@string)
END
SELECT @string
|
Once
we run above query we will get output like as shown below
Output:
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
4 comments :
Sir, please explain the what's work PATINDEX and STUFF.
Thanks for your article. it is very much helpful to me.
please explainPATINDEX and STUFF.
please tell me hoe to remove space
Note: Only a member of this blog may post a comment.