2014-10-27 54 views
0

我的XML代码如下,我想要得到的“流程引擎 - > ID”?我怎样才能在使用SQL如何查询XML值,并从SQL Server表属性

"<?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>" 

谢谢提前.......

回答

1

试试这个 -

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) 
+0

感谢您的答复,我不能申报像@ temp1中XML,我得到错误 – steve 2014-10-27 11:12:10

+0

哪些错误您收到? – 2014-10-27 11:13:52

+0

当我在sql服务器中执行此操作时,它仅在第1行显示错误,而且没有显示其他信息 – steve 2014-10-27 11:16:24