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?