Help with XML - please

  • Hello

    I have no experience of xml. I urgently need to create an xml output. The output I require is

    --

    --

    --

    --

    --

    --

    --

    And the query I have is

    SELECT

    , T.ID

    , C.Country

    , C.City

    , C.Zip

    , C.Region

    FROM SalesOffice C

    INNER JOIN Team T

    ON T.Office = C.Office

    WHERE T.Team = @Team

    How do I get the quey to look like the XML? I need to use FRO XML Explicit, to fit in with other code. Please can someone help me out?

    Many thanks

  • There are several ways of turning this into XML. How do you want the XML document to look?

    You could have everything listed as Elements in the root:

    root

    Element1 value /Element1

    Element2 value /Element2

    /root

    or you could have nested Elements & Attributes:

    root

    Customers

    Element 1 value /Element1

    /Customers

    /root

    Or all sorts of variations on this theme. Also, do you want to include NULL values or not?

    BTW, I did not include angle brackets in the above examples because the site doesn't parse them properly. Just mentally insert them whereever they need to be.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Just add the following after your WHERE clause.

    FOR XML RAW('Team'), TYPE, ELEMENTS

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

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