开发者

How do I insert values from an XML document into a temp table, in SQL Server?

开发者 https://www.devze.com 2022-12-08 19:45 出处:网络
Iam having one SP for which the input is a XML document . I want to insert the values from the XML into a temp table . How i can implement this on开发者_高级运维e ...?CREATE TABLE [dbo].[myTable]

Iam having one SP for which the input is a XML document . I want to insert the values from the XML into a temp table . How i can implement this on开发者_高级运维e ...?


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号