jbliss02
2/21/2016 - 9:52 AM

SQL Server Parse XML

SQL Server Parse XML

DECLARE @xml xml
SET @xml ='<CAPTUREINFO>
	<captureId>465456456</captureId>
	<MOVEMENTS>
		<MOVEMENT>
			<frameStart>1</frameStart>
			<frameEnd>1</frameEnd>
		</MOVEMENT>
		<MOVEMENT>
			<frameStart>12</frameStart>
			<frameEnd>88</frameEnd>
		</MOVEMENT>
	</MOVEMENTS>
</CAPTUREINFO>' 

DECLARE @captureId VARCHAR(100)
SET @captureId = (
	SELECT TOP(1)
	Tbl.Col.value('captureId[1]', 'varchar(100)') captureInfo
	FROM  @xml.nodes('//CAPTUREINFO') Tbl(Col)  
)
SELECT  
	    @captureId captureId,	
      Tbl.Col.value('frameStart[1]', 'int') frameStart,
	    Tbl.Col.value('frameEnd[1]', 'int') frameEnd
FROM   @xml.nodes('//CAPTUREINFO/MOVEMENTS/MOVEMENT') Tbl(Col)