Hi,
We are looking at a scenario of stripping a set of columns (like address for example) of a certain set of punctuation marks. We are currently using a user-defined scalar function containing a set of simple replace statements for this purpose. We are looking at a base table consisting of lakhs of records and we need to obtain this punctuation stripped data across a set of 10 columns.
This activity is turning out to be performance degrading and I am looking at the option of rewriting this function in a performance efficient manner.
PFB the function currenly being used:
Create function [dbo].[ufn_RemovePunctuation] ( @String varchar (255) ) returns varchar(255) as Begin if(@string is NULL or @string='') set @string='' else if(@string like '%[^a-z][^0-9]%') begin set @String = replace(@String, ',', ' ') set @String = replace(@String, '&', ' ') set @String = replace(@String, '.', ' ') set @String = replace(@String, '~', ' ') set @String = replace(@String, '''s', ' S') set @String = replace(@String, '''', ' ') set @String = replace(@String, '"', ' ') set @String = replace(@String, ';', ' ') set @String = replace(@String, '-', ' ') set @String = replace(@String, 'c/o', ' ') set @String = replace(@String, '/', ' ') set @String = replace(@String, '(', ' ') set @String = replace(@String, ')', ' ') set @String = replace(@String, ' ', ' ') set @String = replace(@String, ' ', ' ') set @String = ltrim(rtrim(@String)) end Return @String End GO ------------------ DECLARE @List TABLE (Word nvarchar(200)) INSERT @List VALUES ('Jay c/o jk, No. ~226 (first & second cross street''s ) - "Block 1/2"; ') -->Jay jk No 226 first second cross street S Block 1 2 INSERT @List VALUES ('- "~Happy" ;') -->HappyINSERT @List VALUES ('Very Happy')-->VERY Happy SELECT word,dbo.ufn_RemovePunctuation(word) FROM @List
Have already tried out the approach of having the symbols in a table variable and using a select statement to manipulate the @string variable. No luck! :(
Any leads or help would be very much appreciated.
Thanks.
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>