May 13, 2004 at 9:58 am
May 14, 2004 at 2:04 am
select * from
(Select ColumnA, Count(ColumnB) as ColB From MyTable Where ColumnA='Something' Group by ColumnA Sort By ColumnA) a
May 14, 2004 at 8:38 am
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
May 17, 2004 at 11:18 am
May 17, 2004 at 2:29 pm
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