Thursday, 8 October 2015

get Element value from xml

declare @Text xml ;
set @Text= '<?xml version="1.0" encoding="utf-8"?>
<Project>

    <System_Record_ID><![CDATA[35]]></System_Record_ID>
      <Project_ID><![CDATA[1100]]></Project_ID>
 
</Project>'

;with t as (select @Text [xmlcolumn])
--select * from t
SELECT  x.a.value('(System_Record_ID)[1]','nvarchar(max)') as [System_Record_ID]
,       x.a.value('(Project_ID)[1]','nvarchar(max)') as [Project_ID]
FROM   t
cross apply

t.xmlcolumn.nodes('//Project') x(a)

No comments:

Post a Comment