Calculate Workingdays including Holidays with T-SQL

Calculate Workingdays including Holidays with T-SQL

Erwin

by Erwin | Dec 10, 2019

Calculate Workingdays between 2 Date columns

Recently I have been getting some questions from my customers, can I calculate the number of workdays between 2 dates? Of course my answer was, yes you can. But I do want certain closing dates and holidays of our company not to be included either. That became a little bit more difficult. Eventually I was able to solve this and would like to share that with you.

What do you need as a minimum.

A Date Dimension that includes the day of the week and a fact in which you want to calculate the number of workdays between 2 dates.

WeekendDay

First of all we need to create a table or view where we define our Holidays and Closing Days.

In my case I just created a simple view where I've defined my Holidays, there are more ways to achieve this functionality, but this works as well.

Holidays

After we've created our Holidays we need to create the the following Function:

Businessdays

Finally include this function in your Query.

If we want to know how many workingdays there are between OrderDate 2019-05-29 and ExpectedDeliverydate 2019-06-18 we call the function dbo.fnBusinessday(OrderDate , ExpectedDeliverydate ), the result will be 12.

This is because we have defined 2019-05-30 and 2019-06-10 as Holidays and in between we have 3 weekends.

WorkingDays

If there are no holidays then only the weekend days are not included.

WorkingDaysNoHolidays

With the above method you can use the calculation dynamically every time.

If there are any questions, please leave them in the comments below.

The sample code can be found here.

Feel free to leave a comment

Book of News Microsoft Ignite 2019

Erwin

by Erwin | Nov 7, 2019

Microsoft Ignite 2019

MSIgnite 2019 has almost come to an end. A lot of new Annoucement have been released and presented.  Would you also like to know which announcements have been made?

Microsoft has released during MSIgnite a "Book of News". This book contains all new announcements made on MSIgnite and with all different subjects such as Dataplatform, PowerBI, Power Automate(new name for Microsoft Flow), Power Virtual Agents, Azure ARC, Azure Security. Azure Synapse Analytics(former Azure SQL DW) and much more.

Sam Cogan wrote a short blog post of all the new features:

https://samcogan.com/azure-announcements-from-microsoft-ignite/

https://erwindekreuk.com/wp-content/uploads/2019/11/Ignite_2019_1573153923.pdf

Feel free to leave a comment

My Session at DataMindsConnect 2019

My Session at DataMindsConnect 2019

DataMindsConnect 2019

Date: 7 and 8 th October

Location: Lamot Mechelen

Conference number 3 within 7 days and this time in Mechelen.The location for this conference is in an old beer brewery in the center of Mechelen. Datamindsconnect is the largest Dataplatform event of the BeLux with more than 400 participants. Day 1 consists of various Pre-cons and day 2 consists of 36 different sessions.

Speaking Dinner

Where else can the speaker dinner be held in Belgium? A Belgian beer café with a tasty barbeque. Was a very successful evening with a beer tasting with chocolate at the end. The owner was very proud and enthusiastic about the different tastes.

Thank you

Benni and all other members of the organization and volunteers, thanks for the hospitality, it was again well organized. All sponsors thank you for your support of the event, because without you,  organizing an event is not possible. I am already looking forward to see you all next year.

The presentations of DatamindsConnect and sample code can be found here.

Datagrillen: Data, Bratwurst und Beer

Data, Bratwurst and Beer An event that started 5 years ago as a small event, that has grown into an event with 200 participants, 50+ sessions, 5 tracks, 2 days and a BBQ in a small place in Germany, called Lingen. William Durkin and Ben Weissman are the main…

Data Saturday Stockholm

Data Saturday Stockholm Bra så alla tillbaka personligen This means great so everyone back in person. Last weekend I had the honor to speak at Data Saturday in Stockholm. About one of my favourite topics Azure Synapse Analytics. It was nice to see everyone in person…

My Virtual Session DataSaturday #1 Pordenone

DATA SATURDAY #1 PORDENONE This Saturday I’ve been speaking during DataSaturday #1 Pordenono. The first ever DataSaturday after Pass has retired. If you want to visit more Datasaturday events please visit the Data Saturdays event page. Azure Purview I presented a…

DataSaturday NL 2019

Recording of my session on DataSaturdayNL 2019 Can we store our Connectionstrings or BlobStorageKeys or other Secretvalues somewhere else then in Azure Data Factory(ADF)? Yes you can! You can store these valuable secrets in Azure Key Vault(AKV). But how can we achieve…

Data:Scotland

Data: Scotland 2022 Microsoft Purview Scotland’s Data Community Conference happened this year again in Glasgow. This years event was happening in  a sunny Glasgow, more then 400 attendees and more then 50 sessions. It was great to see so many people live again. I…

SQLBits 2020(Video)

All sessions of SQLBits 2020 have been made available to everyone and can now be viewed via their Youtube channel. To make it easier to find a recording of your choice, a number of playlists have been created: Developer SQLBits 2020 – Developer sessions High…

My Virtual Session Scottish Summit 2021

Scottisch Summit 2021 This Saturday I’ve been speaking during Scottisch Summit 2021. It was my first Summit, but is was a great event, with more than  400 sessions covering the full Microsoft Stack in 7 different language English, Spanish, German, French, Italian,…

Data Toboggan January 2022 (Video)

Recording of my session during the Data Toboggan January 2022 conference. Dealing with different roles in Azure Synapse Analytics

Watch the MS Ignite sessions on-demand

MS Ignite Sessions MS Ignite 2020 was this year a virtual event. Most of the sessions were live in the evenings and the other sessions were available at different times in different time zones. Compliments to the MS Ignite team for organizing such a great event Most…

Speaking at SQLBits in London (postponed to September 2020)

SQLBits 2020 SQLBits is the largest Microsoft Data Platform conference in Europe taking place between 29nd September and 3rd October2020 at the Excel London. Proud to be speaking I am very proud and happy that one of my sessions was selected for SQLBits. It’s not the…

My Sessions at DataSaturdayNL 2019

My Sessions at DataSaturdayNL 2019

Erwin

by Erwin | Oct 13, 2019

DataSaturday NL 2019

Date: 5 th October

Location: Pathé Leidsche Rijn

Data Saturday Holland is the new name for SQL Saturday Holland. A new start a new location and wow what a top location, Pathé Leidsche Rijn. A cinema with 7 screens and ranging from 180 to 668 seats.

Speaking Dinner

The speaker dinner on Friday evening started with a climb of the Dom tower in Utrecht. Unfortunately, due to the renovation, we were unable to reach the top entirely, but we have achieved the 318 steps upwards. At the same time we were briefed about the history of this tower. After the climb we had a nice dinner together.

Event

Saturday the day of the event started early, the event was sold out with 750 tickets. Due to illness of 1 of the speakers I was asked to give an extra session. It's always an honor when they ask you to do an extra session. There was not much time left to prepare, but it worked out eventually. After this session the other session followed immediately. I did this session together with Ahmed Mansour. I had never did co-present a session before, but I really enjoyed it and will certainly do this more often. It brings a lot of variety during a session, but the session also becomes more interactive. In addition, the fun Ahmed and I had during the preparations was definitely worth it.

Thank you

Thanks again to the organization and the crew, and of course all sponsors because without sponsors it is almost impossible to organize such a big event. As usual, it was another top event and I am already looking forward to next year.

The presentations of DataSaturdayNL and sample code can be found here.

Recorded Sessions

This is the first time I have recorded a session. Nice to see again, but also to learn from it again.

Feel free to leave a comment

DataSaturday NL 2019

DataSaturday NL 2019

Recording of my session on DataSaturdayNL 2019 Can we store our Connectionstrings or BlobStorageKeys or other Secretvalues somewhere else then in Azure Data Factory(ADF)? Yes you can! You can store these valuable secrets in Azure Key Vault(AKV). But how can we achieve this in ADF? And finally how do we deploy our DataFactories in Azure Dev Ops to Test, Acceptance and Production environments with these Secrets ? Can this be setup dynamically? During this session I will give answers on all of these questions. You will learn how to setup your Azure Key Vault, connect these secrets in ADF and finally deploy these secrets dynamically in Azure Dev Ops.

Recording of my session which I co-presented with Ahmed Mansour on DataSaturdayNL 2019 During this session we will walk you through all the different Tiers in Azure, DTU, Vcore, Serverless and Managed Instance and will provide examples when to use which Tier. We will also show you the Microsoft Data Migration Assesment (DMA). This tool will help you to decide which tier you should choose.