[英]SQL fetch xml data attribute and values from non xml type column
如何使用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中的結束標記</message>
,但是如果添加了結束標記,則可以使用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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.