Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 24th, 2008, 12:13 PM
Authorized User
 
Join Date: Jan 2007
Location: , , USA.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jonsey Send a message via Yahoo to jonsey
Default calculating work_days

I have a table what has a set of start_dt and end_dt. What I'm looking for is within SQL figuring out the number of working days between two dates. The working days would only be Monday - Friday not including holidays. Any help would be great.


Thanks in Advance
Jonsey

Reply With Quote
  #2 (permalink)  
Old February 5th, 2008, 05:37 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So you want a 1 for every Mon thru friday and a zero for every sat and sunday.

There are two different methods for doing this. One is to create a date table and put in one row for every day and have a collumn with a value of 1 if its a work day or not. Then you relate on day to that table and sum this column.

Another shortcut is to do a case statement and sum it. I don't have a SQL server available to me to test it right now but here is the basic idea.

sum (case somedate when monday = 1
                   when tuesday = 1
                   when wed = 1
                   when thur = 1
                   when fri = 1
                   else 0
     end
    )

You can determine the mon-friday using date part. It's not the exact code but this should give you the idea.


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating time Marta Access 0 April 15th, 2008 10:34 PM
Calculating ashik112 ASP.NET 1.0 and 1.1 Basics 2 February 14th, 2007 12:49 PM
calculating grand total blkskullwork Javascript 2 December 18th, 2006 10:36 AM
calculating values aceconcepts PHP How-To 0 February 16th, 2006 09:01 AM



All times are GMT -4. The time now is 07:21 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.