0

I have the xml code as below,I want to get the "processEngine -> id" how can I get that using sql

"<?xml version="1.0" encoding="UTF-8"?>
<processEngine id="5077000" instanceName="bg2-dev.excers">
   <controller heartBeat="2014-10-27T15:59:50"/>
   <loader heartBeat="2014-10-27T16:01:00" queueLength="62"/>
   <conditionWaitList queueLength="52"/>
   <retryWaitList queueLength="0"/>
   <actionWaitList queueLength="0"/>
   <PreConditionPipelineManager load="1.463905239430332E-6" noOfPipelines="5" queueLength="0"
                                recentLoad="1.1947981003500136E-5">
      <pipeline heartBeat="2014-10-27T16:01:01" index="4" load="7.216747673537921E-6"
                name="Pre Condition Pipeline 0"
                recentLoad="5.963712649181781E-5"
                runTime="6811"
                running="false"
                startTime="2014-10-16T17:59:18"/>
</processEngine>"

Thanks in advance.......

1 Answer 1

1

Try this -

DECLARE @temp1 XML

SELECT @temp1 = '<?xml version="1.0" encoding="UTF-8"?>
<processEngine id="5077000" instanceName="bg2-dev.excers">
  <controller heartBeat="2014-10-27T15:59:50" />
  <loader heartBeat="2014-10-27T16:01:00" queueLength="62" />
  <conditionWaitList queueLength="52" />
  <retryWaitList queueLength="0" />
  <actionWaitList queueLength="0" />
  <pipeline heartBeat="2014-10-27T16:01:01" index="4" load="7.216747673537921E-6" name="Pre Condition Pipeline 0" recentLoad="5.963712649181781E-5" runTime="6811" running="false" startTime="2014-10-16T17:59:18" />
</processEngine>'

SELECT
    a.b.value('@id', 'varchar(10)') value
FROM
    @temp1.nodes('/processEngine') a(b)
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the response,I am not able to declare like @temp1 XML,I am getting error
when I excecute this in sql server,it is showing error at line 1 only no additional info is displaying
Which version of sql server you are using ? because i have tested above code in SQL Server 2008 and its running fine...
What version of SQL Server are you running? The XML data type was introduced in SQL Server 2005.
I am using sql server 2008 R2,I am executing this query in sql developer Version 4.0.1.14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.