473,732 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5115

"Nils Magnus Englund" <ni************ *****@orkfin.no > wrote in message
news:2r******** ************@ne ws.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
1393
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 exclude or the days to actually run the job (last business day) in a table. Is there a way to do this? Thanks.
8
1864
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
3144
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 known. What approach would you advise to tally up the number of holidays, saturdays and sundays between any 2 dates in the range of my records in this table?
34
7478
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 work on a Monday through Friday schedule. For these employees, when a holiday falls on a nonworkday -- Saturday or Sunday -- the holiday usually is observed on Monday (if the holiday falls on Sunday) or Friday (if the holiday falls on Saturday)....
2
5190
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 some code on the Web hard coded holidays, then populate on the calendar. Is it possible to do calendar data binding? Thanks kai
4
3005
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
3598
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! I'm working on setting up a shopping cart for a one-product web site, and I'm using HTML and CSS, with ASP for the shopping cart. The ASP takes the information from the form on the shopping cart, and formats it in to two e-mails: one for the company...
1
2892
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 is 35 days in the future. I need this date to exclude weekends and my company's holidays. I have a separate Holidays table ready. I am not able to figure this one out, can anyone help? I need to get this working on a few different check boxes,...
2
1913
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 of the holidays, but I'm not certain how to work it into the code. Any assistance is greatly appreciated. Public Function addWorkDays(DateInput As Date, intDays As Integer) As Date 'Function that only adds days if they are workdays...
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9181
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.