我嘗試將XML文件添加到SQL 2008如何插入XML到SQL
我的XML:
<ItemList>
<Section Index="0" Name="cat0">
<Item Index="0" Slot="0" />
<Item Index="1" Slot="0" />
</Section>
<Section Index="1" Name="cat1">
<Item Index="33" Slot="0" />
<Item Index="54" Slot="0" />
</Section>
<Section Index="2" Name="cat2">
<Item Index="55" Slot="0" />
<Item Index="78" Slot="0" />
</Section>
</ItemList>
SQL列:
Name = Section Name,
Cat = Section Index,
Index = Item Index,
Slot = Item Slot.
我的例子:
DECLARE @input XML = 'MY XML file'
SELECT
Name = XCol.value('@Index','varchar(25)'),
Cat = XCol.value('@Name','varchar(25)'),
[Index] = 'Unknown', /* Index from <Item>*/
Slot = 'Unknown' /* Slot from <Item> */
FROM @input.nodes('/ItemList/Section') AS test(XCol)
我不知道如何從「Item」中添加值。
非常感謝!
非常感謝! – MeTa