Please help with query

Posts   
 
    
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 02-Aug-2006 20:37:29   

I just created a Calendar table from the this article http://www.aspfaq.com/show.asp?id=2519 and now need help creating a query for it.

Here is the query that I'm trying to write using the CalendarEntity.

SELECT COUNT(*) FROM dbo.Calendar
    WHERE IsWeekday = 1
    AND IsHoliday = 0
    AND DateTime >= '20040401' AND DateTime < '20040501'

Here is the code that I have so far.

public int GetNumberOfWorkDaysInWeek()
{
    using(WSDataAccessAdapter adapter = new WSDataAccessAdapter(DBUtil.ConnectionString))
    {
        IExpression expression = new Expression();

        // Filter for working days.
        IPredicateExpression filter = new PredicateExpression();
        filter.Add(CalendarFields.IsWeekday == 1);
        filter.Add(CalendarFields.IsHoliday == 0);

        // Filter for the current month.
        filter.Add(CalendarFields.DateTime >= 20060801);
        filter.AddWithAnd(CalendarFields.DateTime < 20060801);

        int count = (int)adapter.GetScalar(CalendarFields.DateTime, expression, AggregateFunction.Count, filter);
        return count;
    }
}

I don't understand what I need the expression for in this query. Why can't I do this using only the field, aggregate, and filter?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 03-Aug-2006 02:52:26   

I would think you could as long as the field was unique.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 03-Aug-2006 10:43:23   

Just pass null for the expression.

Frans Bouma | Lead developer LLBLGen Pro
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 04-Aug-2006 00:18:41   

Thank you that did it. I guess I was passing the expression in wrong.