473,396 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Holidays in SQL Server

Hi!

I have a large table in SQL Server 2000 with a datetime-column 'dt'. I want
to select all rows from that table, excluding days which fall on holidays or
weekends. What is the best way to accomplish this? I considered creating a
new table called "holidays" and then selecting all rows (sort of "where not
in (select * from holidays)") , but I was looking for a better solution
since that implies that I have to populate the "holidays" table.

Suggestions are welcome!
Sincerely,
Nils Magnus Englund
Jul 20 '05 #1
2 5079

"Nils Magnus Englund" <ni*****************@orkfin.no> wrote in message
news:2r********************@news.telia.no...
Hi!

I have a large table in SQL Server 2000 with a datetime-column 'dt'. I want to select all rows from that table, excluding days which fall on holidays or weekends. What is the best way to accomplish this? I considered creating a
new table called "holidays" and then selecting all rows (sort of "where not in (select * from holidays)") , but I was looking for a better solution
since that implies that I have to populate the "holidays" table.
That's probably your best idea.

Your holidays may not be mine.


Suggestions are welcome!
Sincerely,
Nils Magnus Englund

Jul 20 '05 #2
Nils Magnus Englund (ni*****************@orkfin.no) writes:
I have a large table in SQL Server 2000 with a datetime-column 'dt'. I
want to select all rows from that table, excluding days which fall on
holidays or weekends. What is the best way to accomplish this? I
considered creating a new table called "holidays" and then selecting all
rows (sort of "where not in (select * from holidays)") , but I was
looking for a better solution since that implies that I have to populate
the "holidays" table.


And how would you expect SQL Server to know about syttende maj or when
Midsummer is?

You can of course make the holidays table more or less sophisticated.
You can just put in all Mondays to Fridays that are not dates from now
to 2020 or whatever.

You can also write a stored procedure that fills in the table given the
rules about currently known holidays. You would need to find data on
where Easter falls, to determine days for Easter, Whitsun and Ascenion Day.

Yet an alternative is to put all days in that table, and then a flag
whether the day is a working day or not, no matter whether it's Friday
or Sunday.

And finally, for the SELECT it self I prefer:

SELECT *
FROM tbl t
WHERE NOT EXISTS (SELECT *
FROM holidays h
WHERE t.date = h.date)
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jason | last post by:
How can I create a custom sql server job schedule? I need to create a job that will run on the last business day of each month (excluding designated holidays). I could either load the holidays to...
8
by: Bob | last post by:
In .NET, is there an easy way to determine State Holidays, such as Thanksgiving, Memorial day, etc? Any reference is appreciated.
2
by: MLH | last post by:
With a table of holidays and A97's date fn's - how best to count weekends and holidays between two dates? My holiday table has 4 fields. I will be adding records to it each year as info becomes...
34
by: MLH | last post by:
http://www.opm.gov/Fedhol/ http://www.opm.gov/Fedhol/2008.asp Federal law (5 U.S.C. 6103) establishes the following public holidays for Federal employees. Please note that most Federal employees...
2
by: kai | last post by:
Hi, I use ASP.NET 2.0 and SQL Server 2005. I try to create calendar control which loads all the holidays from a SQL Server 2005 table, and on the calendar , all the holidays will displayed. I saw...
4
by: Simon | last post by:
By default, days in the calendar control are simply displayed as numbers, I want to show some days in a different color in this control. What is the best way to do that? Thanks very much.
3
by: graphicssl | last post by:
Okay, so first of all, I'm a designer first and a light coder second (I'm only really trained with HTML and CSS). So I apologize for having to post about something that's probably super-trivial! ...
1
by: tmichler | last post by:
I have searched, but everything I'm finding is not really answering my question. I have a field on a form that is calculated when a chk box is clicked. It is calculating a date to follow up that...
2
by: Stephanie Moll | last post by:
Hello. I am using the below code courtesy of The Smiley Coder which works beautifully. I would now like to carve out holidays in addition to the weekends. I believe I will have to create a table...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.