【发布时间】:2019-11-18 19:58:38
【问题描述】:
我在这样的列中有一些 xml。
<ScopedWorkflowConfiguration xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/workflow/2012/xaml/activities">
<appSettings>
<AppSetting>
<Key>CurrentWebUri</Key>
<Value>http://myurl.org</Value>
</AppSetting>
<AppSetting>
<Key>SomethingElse</Key>
<Value>1</Value>
</AppSetting>
<AppSetting>
<Key>AnotherThing</Key>
<Value>420</Value>
</AppSetting>
</appSettings>
</ScopedWorkflowConfiguration>
试图选择 Value 节点的值。
;WITH Casted AS (SELECT t.Id, t.[Configuration] As XmlData FROM dbo.MyTable AS t)
Select Distinct
Id
,pv.value('//*:Key="CurrentWebUri"/Value', 'nvarchar(max)') As CurrentWebUri
From
Casted
Cross Apply Casted.XmlData.nodes(N'//*:ScopedWorkflowConfiguration//*:appSettings//*:AppSetting') AS A(pv)
我知道我很接近 - 但我在此处的语法上遇到了问题://:Key="CurrentWebUri"/Value*
上面的查询导致这个错误:
/需要一个节点或一组节点
你能帮忙吗?
添加一个结果集以供参考以进一步阐明我所追求的:
+----+------------------+------------------+------------------+
| ID | CurrentWebUri | SomethingElse | AnotherThing |
+----+------------------+------------------+------------------+
| 1 | example.org | 1 | 420 |
+----+------------------+------------------+------------------+
| 2 | example.com | 6 | 29 |
+----+------------------+------------------+------------------+
【问题讨论】:
标签: sql xml xquery xquery-sql