Handling Special Characters in SQL Server using Function

CREATE FUNCTION [dbo].[f_HandleSpChar](@v_xml_String varchar(max)) RETURNS VARCHAR(MAX)  
AS  
  
BEGIN   
   
 Declare @v_xml_output varchar(MAX) 
 
set @v_xml_output=replace(@v_xml_String,'¡','¡')
				 set @v_xml_output=replace(@v_xml_output,'¢','¢')
				 set @v_xml_output=replace(@v_xml_output,'£','£')
				 set @v_xml_output=replace(@v_xml_output,'¤','¤')
				 set @v_xml_output=replace(@v_xml_output,'¥','¥')
				 set @v_xml_output=replace(@v_xml_output,'¦','¦')
				 set @v_xml_output=replace(@v_xml_output,'§','§')
				 set @v_xml_output=replace(@v_xml_output,'¨','¨')
				 set @v_xml_output=replace(@v_xml_output,'©','©')
				 set @v_xml_output=replace(@v_xml_output,'ª','ª')
				 set @v_xml_output=replace(@v_xml_output,'«','«')
				 set @v_xml_output=replace(@v_xml_output,'¬','¬')
				 set @v_xml_output=replace(@v_xml_output,'®','®')
				 set @v_xml_output=replace(@v_xml_output,'¯','¯')
				 set @v_xml_output=replace(@v_xml_output,'°','°')
				 set @v_xml_output=replace(@v_xml_output,'±','±')
				 set @v_xml_output=replace(@v_xml_output,'²','²')
				 set @v_xml_output=replace(@v_xml_output,'³','³')
				 set @v_xml_output=replace(@v_xml_output,'´','´')
				 set @v_xml_output=replace(@v_xml_output,'µ','µ')
				 set @v_xml_output=replace(@v_xml_output,'¶','¶')
				 set @v_xml_output=replace(@v_xml_output,'·','·')
				 set @v_xml_output=replace(@v_xml_output,'¸','¸')
				 set @v_xml_output=replace(@v_xml_output,'¹','¹')
				 set @v_xml_output=replace(@v_xml_output,'º','º')
				 set @v_xml_output=replace(@v_xml_output,'»','»')
				 set @v_xml_output=replace(@v_xml_output,'¼','¼')
				 set @v_xml_output=replace(@v_xml_output,'½','½')
				 set @v_xml_output=replace(@v_xml_output,'¾','¾')
				 set @v_xml_output=replace(@v_xml_output,'¿','¿')
				 set @v_xml_output=replace(@v_xml_output,'–','–')
				 set @v_xml_output=replace(@v_xml_output,'—','—')
				 set @v_xml_output=replace(@v_xml_output,'‘','‘')
				 set @v_xml_output=replace(@v_xml_output,'’','’')
				 set @v_xml_output=replace(@v_xml_output,'‚','‚')
				 set @v_xml_output=replace(@v_xml_output,'“','“')
				 set @v_xml_output=replace(@v_xml_output,'”','”')
				 set @v_xml_output=replace(@v_xml_output,'„','„')
				 set @v_xml_output=replace(@v_xml_output,'†','†')
				 set @v_xml_output=replace(@v_xml_output,'‡','‡')
				 set @v_xml_output=replace(@v_xml_output,'•','•')
				 set @v_xml_output=replace(@v_xml_output,'…','…') 
				 set @v_xml_output=replace(@v_xml_output,'‰','‰')
				 set @v_xml_output=replace(@v_xml_output,'€','€')
				 set @v_xml_output=replace(@v_xml_output,'™','™')				
				 set @v_xml_output=replace(@v_xml_output,'”','”') 	                         		 
				
 Return @v_xml_output  
  
END
Advertisements
This entry was posted in MS SQLServer 2008. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s