0

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 one ...?

0

1 Answer 1

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 )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.