Parsing xml data

  • Hi All,

    I have a xml as given below . I need to parse this and retrieve the employee ids present in it and insert into a table.

    declare @data xml='<employeelist>

    <employeeid>7830</employeeid>

    <employeeid>7831</employeeid>

    <employeeid>7832</employeeid>

    </employeelist>';

    Thanks

  • use below..

    SELECT a.c.value('(.)', 'varchar(100)') [EmpID]

    FROM @data.nodes ('employeelist/employeeid') a ( c )

    It's upto you to use Varchar or INT.. I just use Varchar for alphanumeric data...

    Good Luck 🙂 .. Visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply