confused with the HAVING

Posts   
 
    
rai
User
Posts: 41
Joined: 25-Jan-2007
# Posted on: 25-Feb-2008 03:40:34   

I am using LLBLgen version 2.5 I am developing the application in Visual Studio 2005 and using sql server 2005. I am using adapter template from llblgen and coding in C#

this is my sql script SELECT SUM(transact.copies) as sumof copies FROM Tranact where code = 'FT' and month = 2 and year = 2008 GROUP BY transact.batch HAVING transact.batch = 200

this is what i had written as a function using llblgen static public int BatchTotal(string pub,int period,int year,int batch) { DataAccessAdapter adapter = new DataAccessAdapter(dbConnectionString()); IPredicate filter = (TransactionsFields.Code == pub & TransactionsFields.Month == period & TransactionsFields.Year == year & TransactionsFields.BatchNo == batch); int value = (int)adapter.GetScalar(TransactionsFields.Copies,null,AggregateFunction.Sum,filter); adapter.Dispose(); return value; }

I am bit confused about the having clause in my sql script. I just want to know what i have done is right and another thing want to ask how about the HAVING clause in my sql script. How can i put it in my function using llblgen.

Please help me out.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Feb-2008 03:54:24   

SELECT SUM(transact.copies) as sumof copies FROM Tranact where code = 'FT' and month = 2 and year = 2008 GROUP BY transact.batch HAVING transact.batch = 200

I don't know what are you trying do but if you just want to return the whole sum and you are grouping by the same column you are filtering I think you could include the transact.batch = 200 in the WHERE clause and delete the GROUP BY part. Test it, I think you should obtain the same results.

another thing want to ask how about the HAVING clause in my sql script. How can i put it in my function using llblgen.

You have to use the overload that receives a groupBy clause and a having clause. You can read the docs for more info.

Please let us know if you need further help.

David Elizondo | LLBLGen Support Team