2015-03-02 56 views
0

如何從下面的XML獲取名稱值到一些變量?如何從xml中將值提取到sql變量中?

<proc 
    name="DB_NAME.dbo.up_SP" 
    thread_allowed="0" 
    operation_id="12" 
    queueCreatedDate="2015-01-12T07:14:00.640" 
    referenceStub="02216CCE-FA4A-4C27-B130-A835F514E22D" 
    callback-sql="UPDATE dbo.SOME_TABLE SET is_running = 0, last_modified_by = 'up_AsyncMessage', last_modified_date = getdate() WHERE async_job_stub = '022000CE-F00-0000-B000-030000022D'" 
    /> 

回答

0
DECLARE @myxml XML 


SET @myxml = '<proc name="DB_NAME.dbo.up_SP" thread_allowed="0" operation_id="12" queueCreatedDate="2015-01-12T07:14:00.640" referenceStub="02216CCE-FA4A-4C27-B130-A835F514E22D" callback-sql="UPDATE dbo.SOME_TABLE SET is_running = 0, last_modified_by = ''up_AsyncMessage'', last_modified_date = getdate() WHERE async_job_stub = ''022000CE-F00-0000-B000-030000022D''"/>' 

SELECT xmlData.A.value('@name', 'VARCHAR(100)') AS DB_Name 
FROM @myxml.nodes('proc') xmlData(a) 
+0

:非常感謝:) – Rose 2015-03-02 21:14:51

相關問題