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
 Woking Days in a month

Author  Topic 

Bhanu_2007
Starting Member

10 Posts

Posted - 2007-11-06 : 03:07:50
Hi frnds,

How to find the no. of working days for any month?

Input : YearMonth - 200702

Output : 20


Thanks in Advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-06 : 03:11:43
Make use of the F_TABLE_DATE function found here at SQLTeam.
SELECT COUNT(*) FROM F_TABLE_DATE('20070101', '20071231')
where [year] = 2007
and [month] = 2
and weekday_name not in ('sat', 'sun')

How do you compensate for holidays?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-06 : 03:13:51
What is the calculation?
Do you want to exclude saturdays and sundays?

You need date table and do query

Select count(*) from datetable
where date between '20070201' and '20070228'
and datename(weekday,date) not in ('saturday','sunday')

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-06 : 03:14:49


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Bhanu_2007
Starting Member

10 Posts

Posted - 2007-11-06 : 04:17:39
Yes, i want to exclude the Saturdays & Sundays
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-06 : 04:21:31
I posted a working solution for you for 66 minutes ago.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Bhanu_2007
Starting Member

10 Posts

Posted - 2007-11-06 : 07:29:18
Thanks Peso
Go to Top of Page
   

- Advertisement -