Retrieving count of each group

Posts   
 
    
Posts: 28
Joined: 17-Oct-2004
# Posted on: 17-Sep-2006 20:49:20   

I'm using LLBLGen 1.0.2005.1 with the self servicing classes. I have a SQL query with a group by clause and I'm interested in retrieving the count for each group. The SQL is as follows:

SELECT ProductName, VendorName, COUNT(*)
    FROM Product
    GROUP BY ProductName, VendorName

So far I have:

ResultsetFields fields = new ResultsetFields(2);
fields.DefineField(ProductFieldIndex.ProductName, 0, AggregateFunction.None)
fields.DefineField(ProductFieldIndex.VendorName, 1, AggregateFunction.None)

GroupByCollection groupBy = new GroupByCollection();
groupBy.Add(fields[0]);
groupBy.Add(fields[1]);

DataTable results = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, results, 0, null, null, null, false, groupBy, null, 0, 0);

How can I add a field to resemble COUNT(*)?

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 17-Sep-2006 21:00:32   

DotNetShannon wrote:

How can I add a field to resemble COUNT(*)?

Add a third column to the query (the primary key of the table would be a good choice), and set its aggregate function to count.

HTH,

Phil