Click here to Skip to main content
12,069,649 members (63,593 online)
Click here to Skip to main content
Add your own
alternative version

Stats

58.8K views
6 bookmarked
Posted

To remove or replace multiple special character from string using sql queries.

, 30 Dec 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
To remove or replace multiple special character from string using sql queries.

In FN_REMOVE_SPECIAL_CHARACTER] we make use of WITH clause CTE to store the resultset of all special character in one row table.To remove unwanted special characters,we pass string input values and apply string's replace funtion having special character match values from CTE table .

CREATE FUNCTION [FN_REMOVE_SPECIAL_CHARACTER] (  
 @INPUT_STRING varchar(300))
RETURNS VARCHAR(300)
AS 
BEGIN
 
--declare @testString varchar(100),
DECLARE @NEWSTRING VARCHAR(100) 
-- set @teststring = '@san?poojari(darsh)'
 SET @NEWSTRING = @INPUT_STRING ; 
With SPECIAL_CHARACTER as
(
SELECT '>' as item
UNION ALL 
SELECT '<' as item
UNION ALL 
SELECT '(' as item
UNION ALL 
SELECT ')' as item
UNION ALL 
SELECT '!' as item
UNION ALL 
SELECT '?' as item
UNION ALL 
SELECT '@' as item
UNION ALL 
SELECT '*' as item
UNION ALL 
SELECT '%' as item
UNION ALL 
SELECT '$' as item
 )
SELECT @NEWSTRING = Replace(@NEWSTRING, ITEM, '') FROM SPECIAL_CHARACTER  
return @NEWSTRING 
END
select dbo.[FN_REMOVE_SPECIAL_CHARACTER] ('@s()antosh')

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

santosh poojari
Technical Lead
India India
Whatsup-->Exploring--> MVC/HTML5/Javascript & Virtualization.......!
www.santoshpoojari.blogspot.com

You may also be interested in...

Comments and Discussions

 
QuestionAvoid multiple special charecters in email address Pin
Member 117321661-Nov-15 22:05
memberMember 117321661-Nov-15 22:05 
GeneralMy vote of 4 Pin
harirg19-Sep-13 19:30
memberharirg19-Sep-13 19:30 
GeneralMy vote of 5 Pin
Amol_B30-Oct-12 21:32
memberAmol_B30-Oct-12 21:32 
GeneralMy vote of 5 Pin
delaramin2fun28-Aug-12 20:41
memberdelaramin2fun28-Aug-12 20:41 
GeneralReason for my vote of 5 Very helpful string function Pin
ying shen30-Nov-11 17:44
memberying shen30-Nov-11 17:44 
Reason for my vote of 5
Very helpful string function
GeneralReason for my vote of 2 it good but nt the best Pin
spydeehunk5-Jan-11 2:57
memberspydeehunk5-Jan-11 2:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160208.1 | Last Updated 30 Dec 2010
Article Copyright 2010 by santosh poojari
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid