我想在存储过程中从 xml 中获取数据,但它为每条记录返回 null 请帮助!
下面是我在存储过程中用于获取记录的脚本:
declare @deviceData xml
set @deviceData =
'<result>
<resultTotalRows>24</resultTotalRows>
<requestedStartRow>0</requestedStartRow>
<resultSize>24</resultSize>
<requestedSize>1000</requestedSize>
<remainingSize>0</remainingSize>
<DiaChannelDataHistoryFull>
<id>
<devConnectwareId>00000000-00000000-00409DFF-FF521221</devConnectwareId>
<ddInstanceName>bpcuff1</ddInstanceName>
<dcChannelName>diastolic</dcChannelName>
<dcdhId>549747901</dcdhId>
</id>
<cstId>6423</cstId>
<xpExtAddr>00:13:A2:00:40:6B:95:43</xpExtAddr>
<dcDataType>0</dcDataType>
<dcdUpdateTime>2012-07-31T20:53:44.000Z</dcdUpdateTime>
<dcdStringValue>82</dcdStringValue>
<dcdIntegerValue>82</dcdIntegerValue>
</DiaChannelDataHistoryFull>
</result>'
declare @xmltable table (PatientID int, GatewayId nvarchar(255), DeviceName nvarchar(255), TimeStamp datetime, Systolic int, Diastolic int, Pulse int, Status nvarchar(255))
insert into @xmltable (PatientID, GatewayId, DeviceName, TimeStamp, Systolic, Diastolic, Pulse, Status)
select
1 as PatientID,
tbl.clms.value('@devConnectwareId','nvarchar(255)') as GatewayId,
tbl.clms.value('@ddInstanceName','nvarchar(255)') as DeviceName,
tbl.clms.value('@dcdUpdateTime','datetime') as TimeStamp,
case tbl.clms.value('@dcChannelName','nvarchar(255)') when 'Systolic' then tbl.clms.value('@dcdStringValue','nvarchar(255)') else null end as Systolic,
case tbl.clms.value('@dcChannelName','nvarchar(255)') when 'Diastolic' then tbl.clms.value('@dcdStringValue','nvarchar(255)') else null end as Diastolic,
case tbl.clms.value('@dcChannelName','nvarchar(255)') when 'Pulse' then tbl.clms.value('@dcdStringValue','nvarchar(255)') else null end as Pulse,
case tbl.clms.value('@dcChannelName','nvarchar(255)') when 'Sample_Status' then tbl.clms.value('@dcdStringValue','nvarchar(255)') else null end as Status
from @deviceData.nodes('/result/DiaChannelDataHistoryFull') tbl(clms)
select * from @xmltable