【发布时间】:2020-04-10 00:53:39
【问题描述】:
我(通常)知道如何使用 SQL Server 从 XML 中导出数据,并且我已经在提取的其余部分这样做了,我只是不知道如何在交叉应用这些东西时让这些值对齐在 XML 标记内。
这有效并返回 XML 标记名称
DECLARE @XML XML
SET @XML= '
<Export>
<CustomInformation name="Customer ID">12345</CustomInformation>
<CustomInformation name="Prepaid">0.00</CustomInformation>
<CustomInformation name="New Amount">0.00</CustomInformation>
</Export>
'
select
Description = CustomInformation.value('@name','nvarchar(max)')
from
@XML.nodes('/Export/CustomInformation') as b(CustomInformation)
这将返回 null
DECLARE @XML XML
SET @XML= '
<Export>
<CustomInformation name="Customer ID">12345</CustomInformation>
<CustomInformation name="Prepaid">0.00</CustomInformation>
<CustomInformation name="New Amount">0.00</CustomInformation>
</Export>
'
select
Description = CustomInformation.value('@name','nvarchar(max)')
,tire_wheel = col2.value('@Prepaid', 'money')
from
@XML.nodes('/Export/CustomInformation') as b(CustomInformation)
cross apply b.CustomInformation.nodes('CustomInformation') as c(col2)
如何让数据与标签名对齐?
【问题讨论】:
标签: sql-server ssms-2017