Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
替换为sql中varchar变量的引号("e)_Sql_Sql Server_Tsql - Fatal编程技术网

替换为sql中varchar变量的引号("e)

替换为sql中varchar变量的引号("e),sql,sql-server,tsql,Sql,Sql Server,Tsql,我试着用“替换”,replace@variable,'',''没有帮助,我得到了XML <tag>&amp quot;Test&amp quot;</tag> 提前感谢如果问题出在select查询中,请尝试下面的sql Declare @text nvarchar(20) = '"Test"' select @text = replace(@text,'"','&quot;') Declare @table table (ID int) Dec

我试着用“替换”,replace@variable,'',''没有帮助,我得到了XML

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

提前感谢

如果问题出在select查询中,请尝试下面的sql

Declare @text nvarchar(20) = '"Test"'
select @text = replace(@text,'"','&quot;')
Declare @table table (ID int)
Declare @xml as nvarchar(Max)

insert into @table values (123)

set @xml=( Select 
    1 as tag,
    Null as Parent,
    @text as [tag!1!!CDATA]
from @table 
for xml Explicit
)

select @xml
改变

SELECT @TestXml

结果:

result
---------------------------------------
<tag><![CDATA[&quot;Test&quot;]]></tag>

删除此行->设置@Text=REPLACE@Text“,”,“,”再试一次。如果删除集合@Text=replace…,结果将是test。问题是,我必须将varchar中的xml值插入并替换为“,”并将其保存到磁盘,因为xmli有更新。它用于保留特殊字符。
SELECT '<tag>' + @TestXml.value('/tag[1]','varchar(max)') + '</tag>'  as 'Word'
Word
-------------------------------
<tag>&quot;Test&quot;</tag>
Declare @text nvarchar(20) = '"Test"'
select @text = replace(@text,'"','&quot;')
Declare @table table (ID int)
Declare @xml as nvarchar(Max)

insert into @table values (123)

set @xml=( Select 
    1 as tag,
    Null as Parent,
    @text as [tag!1!!CDATA]
from @table 
for xml Explicit
)

select @xml
result
---------------------------------------
<tag><![CDATA[&quot;Test&quot;]]></tag>