我正在开发一个SQL Server 2012存储过程。
我想解析这个XML:
<Commissioning>
<Item ProductionId="115100" ItemId="100" ItemPackagingLevelId="1" ItemFlag="0" TimeStamp="2014-04-28T16:02:59.913" Username="" Source="PLS" />
<Item ProductionId="115101" ItemId="101" ItemPackagingLevelId="1" ItemFlag="0" TimeStamp="2014-04-28T16:03:00.113" Username="" Source="PLS" />
<Item ProductionId="115102" ItemId="102" ItemPackagingLevelId="1" ItemFlag="0" TimeStamp="2014-04-28T16:03:00.317" Username="" Source="PLS" />
<Item ProductionId="115103" ItemId="103" ItemPackagingLevelId="1" ItemFlag="0" TimeStamp="2014-04-28T16:03:00.517" Username="" Source="PLS" />
<Item ProductionId="115104" ItemId="104" ItemPackagingLevelId="1" ItemFlag="0" TimeStamp="2014-04-28T16:03:00.727" Username="" Source="PLS" />
</Commissioning>
并在CTE中插入ItemId
和ItemPackagingLevelId
,因为我想对该数据进行一些计算。
我该怎么做?
答案 0 :(得分:1)
喜欢这个......?
;with cte as (
select
x.n.value('./@ItemId','varchar(100)') as ItemID,
x.n.value('./@ItemPackagingLevelId','varchar(100)') as LevelID
from @x.nodes('/Commissioning/Item') x(n)
)
select * from cte