【发布时间】:2019-04-29 14:42:40
【问题描述】:
我在表中有一个 NTEXT 列,其中包含带单引号的 XML 标记数据。我必须用空白替换具有 XML 标记数据和引号的字符串。
我在 col 中有如下数据
<?xml version="1.0" encoding="utf-8" ?> <securesite> <content> <formsections> <version>12</version> <introduction> <p>Based on the product </p> <p>If you are registered for </p> <p> <![CDATA[ **<p><b>Can't see your form in the list below</b></p>** <a href="http://www.testcom.aspx" target="_blank" alt="View forms">View forms</a> ]]> </p><.....
我必须删除字符串
<p><b>Can't see your form in the list below</b></p>
我曾尝试使用以下查询,但没有奏效:
UPDATE Table SET Col = REPLACE( Col, ' <p><b>Can't see your form in the list below</b></p> ', '')
还尝试将单引号替换为''''单引号:
UPDATE Table SET Col = REPLACE( Col, ' <p><b>Can''''t see your form in the list below</b></p> ', '')
我也试过这个:
UPDATE Table SET Col =REPLACE( CAST( col as varchar(max) ), ' <p><b>Can''''t see your form in the list below</b></p> ', '')
也按照建议尝试了
DECLARE @YourOriginalText NVARCHAR(MAX)
DECLARE @YourModifiedText NVARCHAR(MAX)
SELECT @YourOriginalText = CAST(Col AS NVARCHAR(MAX))FROM [Table]
SET @YourModifiedText = REPLACE( CONVERT(NVARCHAR(MAX), Col), N' <p><b>Can''t see your form in the list below</b></p> ', '')
SELECT @YourModifiedText
UPDATE [Table] SET Col= CAST(@YourModifiedText AS NTEXT)
但它也没有奏效。
你能指导我正确的方向并告诉我如何替换文本吗?
【问题讨论】:
-
你试过
SET QUOTED_IDENTIFIER OFF吗?
标签: sql-server tsql sql-server-2008 replace