SQL and XML Exporting

  • I have an SQL database, and I was wandering how to export data from the tables to an XML file – do you know how to do this?

    Also, I would also like to know if you can import XML files into tables of an SQL database?

    Any help would be appreciated!

    cheers

    alan

  • alanm (5/5/2008)


    I have an SQL database, and I was wandering how to export data from the tables to an XML file – do you know how to do this?

    Look at the FOR XML clause of the SELECT statement.

    Also, I would also like to know if you can import XML files into tables of an SQL database?

    Look at the OPENXML statement.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Thanks - managed to use this:

    Select *

    From dbo.Database_User_Profiles

    For XML AUTO

    and it worked fine.

    Question is, where does the file end up on the server? I ran a search but cannot find it!

  • Hello,

    The Select statement returns the output to the output screen.

    'Assuming' you want to get the XML output to the operating system, you can load a table with the ouput in a single column and then use bcp to export it.

    Example table with single column.

    create output_tbl

    ( outrec varchar(1000) null )

    Then use your select statment to load a insert to the output_tlb.

    Then in the operating system .bat use the bcp out command to export it to the sub-directory of your choice.

    Regards,

    Terry

Viewing 4 posts - 1 through 3 (of 3 total)

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