我有一个XML变量@ResultData
,其中包含以下内容:
<EntityKey_x005B__x005D_>
<EntityKey>
<KeyData xmlns="http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey">
<KeyField>
<Field>JournalNum</Field>
<Value>LJRN000071</Value>
</KeyField>
</KeyData>
</EntityKey>
<EntityKey>
<KeyData xmlns="http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey">
<KeyField>
<Field>JournalNum</Field>
<Value>LJRN000072</Value>
</KeyField>
</KeyData>
</EntityKey>
<EntityKey>
<KeyData xmlns="http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey">
<KeyField>
<Field>JournalNum</Field>
<Value>LJRN000073</Value>
</KeyField>
</KeyData>
</EntityKey>
<EntityKey>
<KeyData xmlns="http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey">
<KeyField>
<Field>JournalNum</Field>
<Value>LJRN000074</Value>
</KeyField>
</KeyData>
</EntityKey>
</EntityKey_x005B__x005D_>
但是由于节点上的 xmlns=...
,我似乎无法选择其中的JournalNum值。在 .Net 中,我可以执行类似于 "{http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey}KeyData"
的操作来检索它,但是在 SQL 中我会得到语法错误。
我只想将 Value 节点按文档顺序列出到一个临时表中,但这也行不通....
SELECT IDENTITY(int,1,1) as 'ID',
c.query('(KeyData/KeyField/Value)[1]') as 'JournalNum'
INTO #tmpBatches
FROM @ResultData.nodes('//EntityKey') t(c)
您有什么想法?建议?解决方案?