问题描述
我有一个包含 ntext 数据类型的 XML 列的表.
I have a table include XML column with ntext data type.
CREATE TABLE #Testing ( Id int identity, content ntext ) INSERT INTO #Testing VALUES (N'<?xml version="1.0" encoding="UTF-8"?> <Data <BankAcc><Bankname value="TEST Q?rib Bank "/><AccNum value="TEST1221"/></BankAcc> </Data>')
我想将此数据
I want to insert this data <Owner value="Q?rib"/> into existing ntext data type xml column with code below
update #Testing set content.modify(N'insert <Owner value="Q?rib"/> into (/Data)[1]')
但我收到一个错误:
消息 258,级别 15,状态 1,第 12 行
无法在 ntext 上调用方法
Msg 258, Level 15, State 1, Line 12
Cannot call methods on ntext
所以我尝试使用演员
update #Testing set cast(content as varchar(max)).modify(N'insert <Owner value="Q?rib"/> into (/Data)[1]')
然后我收到此错误消息:
then I got this error message:
消息 102,级别 15,状态 1,第 12 行
'(' 附近的语法不正确.
Msg 102, Level 15, State 1, Line 12
Incorrect syntax near '('.
有什么解决办法吗?
推荐答案
将您的数据类型转换为 nvarchar(max)、varchar(max) 或 varbinary(max)
convert your data type to nvarchar(max), varchar(max) or varbinary(max)
重要!ntext、text 和 image 数据类型将在 SQL Server 的未来版本中删除.避免在新的开发工作中使用这些数据类型,并计划修改当前使用它们的应用程序.请改用 nvarchar(max)、varchar(max) 和 varbinary(max).
IMPORTANT! ntext, text, and image data types will be removed in a future version of SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.
参考
如果它是正确的 xml,那么 XML 数据类型将最适合
If it is proper xml then XML data type will fit best