sql server - Replace " with "e from varchar variable in sql -
i'm trying replace "
"
, replace(@variable,'"','"')
didn't help, in xml got
<tag>& quot;test& quot;</tag>
instead of
<tag>"test"</tag>
example:
declare @text varchar(20) = '"test"' set @text = replace(@text,'"','" ;') 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>"test"</tag>
update
to keep '&' char need <![cdata[...]> try below sql
declare @text nvarchar(20) = '"test"' select @text = replace(@text,'"','"') 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["test"]]></tag>
Comments
Post a Comment