I am stuck at a point where I have to exclude the weekends tickets and need to count the rest tickets(just weekdays).
Let’s suppose:
tickets dates
----------- ----------
123 04/05/2012
231 04/06/2012
111 04/07/2012
112 04/08/2012
113 04/09/2012
So, In the above table we have a data for 5 days including weekday and weekend.
I just need weekday data not the weekend in my final table like this:
tickets dates
----------- ----------
123 04/05/2012
231 04/06/2012
113 04/09/2012
Don’t bother with datefirst. It can cause problems
EDIT:
Datefirst is different from database to database. So you need to set datefirst before using ‘DatePart(dw,dates)’
of the week. That means that every time you run the script you should call that datefirst. In case you decide to put it in a function you are screwed because you can’t use it inside that function. So every time you call that function you rely on people remembering that datefirst part.
My solution does not rely on the individual setting of the database.
What it does is this:
calculate the days between 0 which represent 1900-01-01(a monday) and dates.
modulus 7 of that is a daynumber between 0(monday) and 6(sunday) so less than 5 is a weekday.