Results 1 to 1 of 1
  1. #1
    Join Date
    Feb 2004
    Posts
    1

    Unanswered: FOR XML EXPLICIT

    Hello, I have been a regular here, however this is my 1st time posting.

    I've recently been researching FOR XML EXPLICIT and I noticed something very unusual and I'm hoping someone can clarify what's going on.

    The following SQL Query:
    select top 1 1 as Tag, NULL as Parent,
    NULL as [root!1!root!hide],
    GroupName as [group!2!groupname!element],
    sum_new as [group!2!sum_new!element],
    sum_closed as [group!2!sum_closed!element]
    from mytest
    UNION ALL

    SELECT 2 as Tag, 1 as Parent, NULL,
    GroupName, sum_new, sum_closed
    from mytest
    ORDER BY
    [group!2!groupname!element]
    for xml explicit
    Produces this

    <root>
    <group>
    <groupname>group 1</groupname>
    <sum_new>0</sum_new>
    <sum_closed>0</sum_closed>
    </group>
    <group>
    <groupname>group 2</groupname>
    <sum_new>0</sum_new>
    <sum_closed>0</sum_closed>
    </group>



    <root>

    But if I remove the "Top 1" from "Select Top 1", I no longer have a "top level node"

    <root>
    <group>
    <groupname>group 1</groupname>
    <sum_new>0</sum_new>
    <sum_closed>0</sum_closed>
    </group>
    </root>

    <root>
    <group>
    <groupname>group 2</groupname>
    <sum_new>0</sum_new>
    <sum_closed>0</sum_closed>
    </group>
    </root>



    I accidently added the top 1 but that's what I want it to do, however I just need an explanation on what exactly top 1 is doing in this query.
    Last edited by ispcay; 02-12-04 at 09:18.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •