sql server - Replace " with &quote from varchar variable in sql -


i'm trying replace " &quot, replace(@variable,'"','"') didn't help, in xml got

<tag>&amp quot;test&amp quot;</tag>  

instead of

<tag>&quot;test&quot;</tag> 

example:

declare @text varchar(20) = '"test"' set @text = replace(@text,'"','&quot ;') select @text declare @table table (id int) insert @table     (id) values     (123) declare @testxml xml = (      select         @text     @table tag       xml auto, elements     )    select @testxml 

thanks in advance

if problem in select query, try below sql

change the

select @testxml 

to

select '<tag>' + @testxml.value('/tag[1]','varchar(max)') + '</tag>'  'word' 

you below result in select query:

word ------------------------------- <tag>&quot;test&quot;</tag> 

update

to keep '&' char need <![cdata[...]> try below sql

declare @text nvarchar(20) = '"test"' select @text = replace(@text,'"','&quot;') declare @table table (id int) declare @xml nvarchar(max)  insert @table values (123)  set @xml=( select      1 tag,     null parent,     @text [tag!1!!cdata] @table  xml explicit )  select @xml 

result:

result --------------------------------------- <tag><![cdata[&quot;test&quot;]]></tag> 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -