我想通過TSQL解析/撕碎SQL Server 2008中的XML,其中一個節點具有以下格式的空白屬性,沒有指定值。我似乎無法檢索該值,並將其拋出了所有其他SQL Server解析XML空屬性
這裏是TSQL代碼的什麼是錯的一個PIC(移動列):
declare @doc nvarchar(4000)
set @doc = '
<Objects>
<Object>
<Property Name="Path">some path</Property>
<Property Name="InstanceName">some instance</Property>
<Property Name="result1">0.390630000000003</Property>
<Property Name="result2">63345649697265</Property>
</Object>
<Object>
<Property Name="Path">another path</Property>
<Property Name="InstanceName" />
<Property Name="result1">100</Property>
<Property Name="result2">1002</Property>
</Object>
</Objects>
'
SELECT
item.ref.value('(Property/text())[1]', 'nvarchar(128)') AS Path,
item.ref.value('(Property/text())[2]', 'nvarchar(128)') AS InstanceName,
item.ref.value('(Property/text())[3]', 'nvarchar(128)') AS result1,
item.ref.value('(Property/text())[4]', 'nvarchar(128)') AS result2
FROM (SELECT CAST(@doc AS XML) AS feedXml) feeds(feedXml)
CROSS APPLY feedXml.nodes('/Objects/Object') AS item(ref)
當您運行查詢請注意,InstanceName列是使用另一列中的值填充的,而不是空白,空或空值。
任何幫助表示讚賞。