XML Template Query

  • I have a small issue, here's how my code would normally go:
     
    Select ColumnA, Count(ColumnB) as ColB From MyTable Where ColumnA='Something' Group by ColumnA Sort By ColumnA
     
    The two problems I'm having is one, I get an error that says the group by isn't supported, and two, Something is a dynamic value.
     
    How would I transfer this to a XML Template?
     
    Thanks,
    tibby
  • select * from

    (Select ColumnA, Count(ColumnB) as ColB From MyTable Where ColumnA='Something' Group by ColumnA Sort By ColumnA) a

  • Here is an example I setup with northwind

    file x.xml as defined

    <?xml version ='1.0'?>

    <document xmlns:sql='urn:schemas-microsoft-com:xml-sql' sql:xsl='x.xsl'>

     <sql:header>

         <sql:param name="CustomerID">ANATR</sql:param>

     </sql:header>

     <sql:query>

      SELECT * FROM (Select TOP 100 PERCENT CustomerID, Count(OrderID) OrderCount

      From dbo.Orders

      Where CustomerID = @CustomerID Group by CustomerID Order By CustomerID) Orders

      FOR XML AUTO, ELEMENTS

     </sql:query>

    </document>

    file x.xsl as defined

    <?xml version='1.0'?>

    <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>

     <xsl:template match='Orders'>

             <tr>

       <td>

        <xsl:value-of select='CustomerID'/>

       </td>

       <td>

        <xsl:value-of select='OrderCount'/>

       </td>

      </tr>

     </xsl:template>

      <xsl:template match='/'>

        <html>

     <head>

      <title>XML Test</title>

     </head>

     <style>

      TH {

       background-Color:#0000bb;

       color:#ff0000;

       font-weight:bolder

      }

      TD {

       background-Color:#ffffff

      }

     </style>

          <body bgcolor='#ffffff'>

           

     <table align='center' style='border: solid 1pt #000000;'>

      <tr>

       <th>Customer ID</th>

       <th>Order Count</th>

      </tr>

      <xsl:apply-templates/>

     </table>

          </body>

        </html>

      </xsl:template>

    </xsl:stylesheet>

    Set up my template directory and did the following

    http://address/path/templatedir/x.xml?contenttype=text/html&CustomerID=VINET

  • Just shooting off the hip and looking at your post, how did you get the Group By clause to work?  I'm being told it is not supported in SQLXML...
     
    Thank You,
    tibby
  • If you will look at my query you will notice it is actually a subquery for the GROUP BY expression which is treated like a view to the top query.

    By doing this it assumes my query was select * from (some table or view named ORDERS)  FOR XML ... so it doesn't see the group by being done as FOR XML.

    SELECT * FROM (Select TOP 100 PERCENT CustomerID, Count(OrderID) OrderCount

    From dbo.Orders

    Where CustomerID = @CustomerID Group by CustomerID Order By CustomerID) Orders

    FOR XML AUTO, ELEMENTS

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

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