Grouping date periods (by number of days) but exclude the weekends?

Posted by tonyyeb on Stack Overflow See other posts from Stack Overflow or by tonyyeb
Published on 2010-01-26T11:21:24Z Indexed on 2010/03/27 12:03 UTC
Read the original article Hit count: 159

Filed under:
|
|

I have a table with start and end dates in. My goal is to have a table that has grouped these dates into how many days the period spans. I thought I had the solution with a simple SQL statement (MS SQL Server 2005) but I want to exclude weekends.

SELECT DATEDIFF(D, StartDate, EndDate)+1 AS Days,
 COUNT(ID) as Count 
FROM myDateTable
GROUP BY DATEDIFF(D, StartDate, EndDate)

This gives a record set of:

Days Count
1    4
2    2
4    1
7    2

Is this possible to exclude the weekends in the SQL statement and if not can it be done using ASP and a array perhaps?

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about asp