Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

Posts Tagged ‘advanced querying’

Calculating Work-Days in T-SQL

Posted by Viral Sarvaiya on May 3, 2010


One of the more serious questions in project scheduling, employee planning, and accounting of time is “How many workdays are there?” In other words, given a start date and an end date, how many weekdays (usually a “workday”) are there in the date range including the start date and the end date?

The normal response I get to that question varies but has been limited to “It can’t be done in SQL”, “Ya gotta use a CURSOR”, or “You have to build a table”. This article will take you through all of the logic behind building a nasty fast “Work Day Calculator” function, the crux of which is a single SELECT statement. A fully commented production-worthy UDF is available at the end of this article.

For more details :


Posted in Sql Server | Tagged: , , | Leave a Comment »

%d bloggers like this: