Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.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从非xml类型列获取xml数据属性和值_Sql_Sql Server_Sql Server 2008_Openfire_Sqlxml - Fatal编程技术网

SQL从非xml类型列获取xml数据属性和值

SQL从非xml类型列获取xml数据属性和值,sql,sql-server,sql-server-2008,openfire,sqlxml,Sql,Sql Server,Sql Server 2008,Openfire,Sqlxml,如何使用SQL从非xml类型列检索xml类型数据 我有一张桌子和一列在里面 xml是ntext类型的列 xml列数据示例如下所示 <message to="4075@abc.myftp.org" type="chat" from="5082@abc.myftp.org/e76bea0f"> <body>james bond</body> <active xmlns="http://jabber.org/protocol/chatstates" />

如何使用SQL从非xml类型列检索xml类型数据 我有一张桌子和一列在里面 xml是ntext类型的列

xml列数据示例如下所示

<message to="4075@abc.myftp.org" type="chat" from="5082@abc.myftp.org/e76bea0f">
<body>james bond</body>
<active xmlns="http://jabber.org/protocol/chatstates" />
</message>
我想从属性值和标记值中提取到


请建议

您错过了xml中的结束标记,但如果添加它,您可以使用value函数:

declare @temp table (data ntext)

insert into @temp (data)
select '<message to="4075@abc.myftp.org" type="chat" from="5082@abc.myftp.org/e76bea0f">
<body>james bond</body>
<active xmlns="http://jabber.org/protocol/chatstates" />
</message>'

select
    c.data.value('message[1]/@to', 'nvarchar(max)')
from @temp as t
    outer apply (select cast(data as xml)) as c(data)

感谢@Roman提供的完美答案和快速响应Hi Roman,我正在尝试从PHP应用程序运行此查询,但出现错误/****[nativecode=1934-选择失败,因为以下集合选项的设置不正确:“ANSI_NULLS、QUOTED_IDENTIFIER、CONCAT_NULL_INULL、ANSI_警告、ANSI_PADDING”。请验证集合选项是否正确,可用于索引视图和/或计算列上的索引和/或筛选索引和/或查询通知和/或XML数据类型方法和/或空间索引操作。]******/您能提出建议吗