繁体   English   中英

如何在SQL Server 2005中读取xml?

[英]How to read a xml in SQL Server 2005?

我有这个查询

WITH XMLNAMESPACES (DEFAULT 'http://www.w3.org/2005/Atom') 
select 
cast(idsku as int) idsku,
cast(entregado as int) entregado from #final1 final FOR XML AUTO, ROOT ('clientesxml'), ELEMENTS 

这个回报

<clientesxml xmlns="http://www.w3.org/2005/Atom">
  <final>
    <idsku>191</idsku>
    <entregado>159</entregado>
  </final>
</clientesxml>

我的问题是如何创建一个存储过程,该过程读​​取返回的XML并将其转换为#tempTable

以下是创建proc时可能会派上用场的一些类似方法:

-- Declare some xml
declare @xml xml = '<clientesxml xmlns="http://www.w3.org/2005/Atom">
  <final>
    <idsku>191</idsku>
    <entregado>159</entregado>
  </final>
</clientesxml>'

-- Shred the xml
;with xmlnamespaces (default 'http://www.w3.org/2005/Atom') 
select x.Record.value('idsku[1]', 'int') as idsku
    , x.Record.value('entregado[1]', 'int') as entregado
from @xml.nodes('//clientesxml/final') as x (Record)

-- Shred and insert the xml into a new temp table
;with xmlnamespaces (default 'http://www.w3.org/2005/Atom') 
select x.Record.value('idsku[1]', 'int') as idsku
    , x.Record.value('entregado[1]', 'int') as entregado
into #tempTable
from @xml.nodes('//clientesxml/final') as x (Record)

-- Shred and insert the xml into an existing temp table
;with xmlnamespaces (default 'http://www.w3.org/2005/Atom') 
insert into #tempTable (idsku, entregado)
select x.Record.value('idsku[1]', 'int') as idsku
    , x.Record.value('entregado[1]', 'int') as entregado
from @xml.nodes('//clientesxml/final') as x (Record)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM