Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL - "NetWork Days" Calculation

Author  Topic 

funk.phenomena
Posting Yak Master

121 Posts

Posted - 2011-05-09 : 23:11:51
Hi All! I have the following Columns in a read-only table:

ORDER #
DATE ORDERED
DATE ARRIVED

I'm trying to write a query to display all the fields in the table, plus a column that calculates the amount of business days it took for the order to arrive. I've done searches on this in the past, but I'm still not quite sure on how to use procedures and converts in SQL.

Any help is greatly appreciated!
THANKS!!!

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-05-10 : 02:57:40
select
[DATE ORDERED],
[DATE ARRIVED],
(DATEDIFF(dd, [DATE ORDERED], [DATE ARRIVED]) + 1)
-(DATEDIFF(wk, [DATE ORDERED], [DATE ARRIVED]) * 2)
-(CASE WHEN DATENAME(dw, [DATE ORDERED]) = 'Sunday' THEN 1 ELSE 0 END)
-(CASE WHEN DATENAME(dw, [DATE ARRIVED]) = 'Saturday' THEN 1 ELSE 0 END)
as DaysAmount
from [Order #]

adapted from: http://www.sqlservercentral.com/articles/Advanced+Querying/calculatingworkdays/1660/


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

funk.phenomena
Posting Yak Master

121 Posts

Posted - 2011-05-10 : 10:27:19
You have made my life WAY easier.
Thank you SO much!
Go to Top of Page
   

- Advertisement -