我有一个SP,输入是一个XML文档。我想将XML中的值插入临时表。我如何实现这一个......?
答案 0 :(得分:2)
CREATE TABLE [dbo].[myTable]
(
[a] [int] NULL,
[b] [varchar](50) NULL,
[c] [datetime] NULL
) ;
DECLARE @p_xml XML
SET @p_xml = '<root>
<table a="123">
<b>ABC</b>
<c>2009-10-20</c>
</table>
</root>'
INSERT INTO myTable
( a, b, c)
SELECT
x.mytable.value('@a[1]', 'INT'),
x.mytable.value('b[1]', 'VARCHAR'),
x.mytable.value('c[1]', 'DATETIME')
FROM
@p_xml.nodes('//root/table') AS x ( mytable )