SQL 2005 generates XML comment, array of elements

By admin - Last updated: Monday, November 12, 2007 - Save & Share - Leave a Comment
        'nameValue' AS "@name",
        CAST('<!-- your comment -->' AS XML),
        'anotherValue' AS "another",
        (SELECT 'i' AS "@name", '1' AS "@value" FOR XML PATH('item'), TYPE),
        (SELECT 'j' AS "@name", '2' AS "@value" FOR XML PATH('item'), TYPE)
FOR XML PATH('sample'), ROOT('root')


  <sample name="nameValue">
    <!-- your comment -->
    <item name="i" value="1"></item>
    <item name="j" value="2"></item>

Posted in SQL • Tags: , , , Top Of Page