Click here to Skip to main content
Click here to Skip to main content

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

By , 30 Dec 2010
 

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)

About the Author

santosh poojari
Technical Lead
India India
He is presently working as tech arch in one of the leading IT company.He has total 10 years of experience in C#.net. He is a B.E graduate in Computers from Bombay University.
 
Most of his experiences are in designing architect for end to end solutions. His interest areas are WCF,Spring.net,Architecture- Model View Presenter,UML,Webservice,Performance Engineering/tuning,Design patterns,Generics,Enterprise Library,Regular expressions,Silverlight and WWF.
www.santoshpoojari.blogspot.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5 PinmemberAmol_B30-Oct-12 20:32 
Excellent!
GeneralMy vote of 5 Pinmemberdelaramin2fun28-Aug-12 19:41 
GeneralReason for my vote of 5 Very helpful string function Pinmemberying shen30-Nov-11 16:44 
GeneralReason for my vote of 2 it good but nt the best Pinmemberspydeehunk5-Jan-11 1:57 

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

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

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