Home Forums Programming XML Parsing huge XML file into a database table using sql server RE: Parsing huge XML file into a database table using sql server

  • I wrote a blog on something similar a while back: http://www.olcot.co.uk/sql-blogs/using-xquery-to-create-a-single-xml-node-with-comma-separated-string-from-multiple-xml-nodes

    here is one of a few ways to comma separate the node author for you:

    DECLARE @xml XML

    SELECT @xml = CONVERT(XML, (SELECT * FROM OPENROWSET(BULK N'c:\testxml.xml', SINGLE_BLOB) AS xmldocument), 2)

    SELECT t.c.query('for $x in author

    return

    if (not( ($x) is (author[last()])[1] )) then

    concat($x/text()[1], ",")

    else

    string($x/text()[1])').value('.', 'varchar(200)')

    , t.c.value('(title/text())[1]', 'varchar(150)') AS 'title'

    , t.c.value('(journal/text())[1]', 'varchar(100)') AS 'journal'

    FROM @xml.nodes('//article') AS T(c)