我有一些XML数据存储在SQL Server 2005上的varchar(max)列中.数据的格式为(FQTN =完全限定类型名称):
<?xml version="1.0" encoding="utf-16"?>
<History xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<EntityViews>
<EntityProxy Type="FQTN" Key="386876" />
<EntityProxy Type="FQTN" Key="387981" />
<!-- etc. -->
</EntityViews>
</History>
Run Code Online (Sandbox Code Playgroud)
如何选择Type,Key以便从此列的XML数据中获取单行的表格结果?该表具有名为HistoryId的标识主键.
;with cteCastToXML as (
select CAST(YourColumn as xml) as x
from YourTable
)
select h.ep.value('@Type','varchar(10)') as [Type],
h.ep.value('@Key', 'varchar(10)') as [Key]
from cteCastToXML
cross apply x.nodes('/History/EntityViews/EntityProxy') as h(ep)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10743 次 |
| 最近记录: |