Here is how you can strip all special characters from a column. Here I need to remove all special characters from a column before inserting into database. I wrote this function to reuse this in different places.
CREATE FUNCTION dbo.usfStripSpecailCharactersHope this is useful!!
(
@str VARCHAR(255)
)
RETURNS VARCHAR(255)
AS
BEGIN
WHILE PATINDEX( '%[~,@,#,$,%,&,*,(,),.,]%', @str ) > 0
SET @str = Replace(REPLACE( @str,
SUBSTRING( @str, PATINDEX( '%[~,@,#,$,%,&,*,(,),.,]%', @str ), 1 ),''),'-','')
RETURN @str
END
GO
-- Use this function and pass your string to remove special characters
SELECT dbo.usfStripSpecailCharacters('test#se3#$%#@-32402');
No comments:
Post a Comment