FOR XML PATH('Product')

Posted on 2011-05-02
Last Modified: 2012-05-11
hi experts, i have this query
SELECT ProductID AS "@ProductID",
       Name AS "*",
       Size AS "Description/@Size",
       Color AS "Description/text()"
FROM Production.Product
FOR XML PATH('Product')
can explain to me that means the nomenclature used in select
Question by:enrique_aeo
    LVL 23

    Assisted Solution

    Please check the following link:

    Using PATH Mode

    Author Comment

    is much information, you can explain just what I'm asking. Thanks
    LVL 23

    Accepted Solution

    There you go.  I hope this helps:

    SELECT ProductID AS "@ProductID",      -- Set the attribute <Product ProductID=> to the value of the ProductID column
           Name AS "*",                    -- Set the text of <Product> to the value of the Name column
           Size AS "Description/@Size",    -- Set the attribute <Description Size=> to the value of the Size column
           Color AS "Description/text()"   -- Set the text of <Description> to the value of the Color column
    FROM Production.Product
    ORDER BY Name
    FOR XML PATH('Product')                -- For each row generate a XML Tag <Product>

    Open in new window


    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
    How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now