Trouble Converting XML data to SQL Relational Table Data with XQuery

  • I have data stored in a SQL 2005 database in the XML data type. I am able to extract values for this data using XQuery (see below), but I don't know how to store the data into relational tables so I can report and perform calculations on it.

    /*

    -- Partial data for one row of XML data in a column called "xml":

    -- Query to extract Client_Name and Contact1_Name values

    select description,

    xml.value('(Data/Client_Name/@value)[1]','varchar(200)') as client,

    xml.value('(Data/Contact1_Name/@value)[1]','varchar(200)') as contact1

    from FileStore

    where description = 'Invoice_10013'

    */

    How can I take the extracted values and store them in a table now?

  • INSERT TargetTable (description, client, contact)

    select description,

    xml.value('(Data/Client_Name/@value)[1]','varchar(200)') as client,

    xml.value('(Data/Contact1_Name/@value)[1]','varchar(200)') as contact1

    from FileStore

    where description = 'Invoice_10013'


    N 56°04'39.16"
    E 12°55'05.25"

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

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