sql server 2012 - How to replace special character in sql table and replace by desired character dynamically? -
eg
'è' 'e'
'á'by a
'¾' '3/4'
ó 'o'
'ñ' by'n'
'á' 'a'
not working ...but result above want.
while exsits (select id #tmp_dirtytable) begin -- step 1: read required data row temp table declare @id int declare @special_character varchar(100) declare @special_character_to_replace_with varchar(100) select @id = id, @special_character = special_character, @special_char_bal_bla = #tmp_dirtytable -- step 2: write replace logic here -- step 3: delete row have processed temp table delete #tmp_dirtytable id = @id end
if using sql server, query you
create proc specialcharacterreplacer @tblname varchar(1000), @column_name varchar(1000) begin declare @query varchar(max) set @query = 'update '+@tblname +' set ' +@column_name + ' = dbo.replacespecialcharacter('+@column_name+')' exec(@query) end create function replacespecialcharacter ( @input varchar(max) ) returns varchar(max) begin declare @result varchar(max) set @result = replace(@input,'è','e') set @result = replace(@result,'á','a') set @result = replace(@result,'¾','3/4') set @result = replace(@result,'ó','o') set @result = replace(@result,'ä','a') set @result = replace(@result,'ñ','n') set @result = replace(@result,'á','a') return @result end go
Comments
Post a Comment