filmov
tv
Calculate the next working day (excluding weekends and vacation/holidays) in SQL Server
Показать описание
We can add days fairly easily in SQL Server. But what about the next working day?
My SQL Server Udemy courses are:
----
In this video, I'll show you how to calculate the next working day (excluding weekends and vacation/holidays) in SQL Server. This video is perfect for students and professionals who need to schedule appointments or manage their work schedule.
I'll walk you through the steps needed to calculate the next working day in SQL Server, and I'll provide examples to make the process easier to understand. You'll be able to use this information to manage your work schedule and avoid conflicts with other commitments. So don't wait any longer, watch this video and learn how to calculate the next working day in SQL Server!
The end code is (replace "Less Than" with the appropriate symbol):
DROP TABLE IF EXISTS DateTable;
DROP TABLE IF EXISTS Holidays;
CREATE TABLE DateTable
(Dates Date)
INSERT INTO DateTable
SELECT DATEADD(DAY, ROW_NUMBER() OVER(ORDER BY (SELECT NULL)), '2009-12-31')
CREATE TABLE Holidays
(Holiday date)
INSERT INTO Holidays
VALUES ('2023-12-25'),('2023-12-26'),('2024-01-01')
--SELECT *
--FROM DateTable
--WHERE DATEPART(WEEKDAY, Dates) NOT IN (7, 1)
DECLARE @myDate date = '2023-12-24';
With LEADTable AS (
SELECT Dates, LEAD(Dates, 3) OVER(ORDER BY Dates) as ThreeDaysLater
FROM DateTable
WHERE DATEPART(WEEKDAY, Dates) NOT IN (7, 1)
AND Dates NOT IN (SELECT Holiday FROM Holidays)
)
SELECT *
FROM LEADTable
WHERE Dates = (SELECT MAX(Dates) from DateTable
WHERE DATEPART(WEEKDAY, Dates) NOT IN (7, 1)
AND Dates NOT IN (SELECT Holiday FROM Holidays)
AND Dates
Replace with "Less Than"
----
Links to my website are:
My SQL Server Udemy courses are:
----
In this video, I'll show you how to calculate the next working day (excluding weekends and vacation/holidays) in SQL Server. This video is perfect for students and professionals who need to schedule appointments or manage their work schedule.
I'll walk you through the steps needed to calculate the next working day in SQL Server, and I'll provide examples to make the process easier to understand. You'll be able to use this information to manage your work schedule and avoid conflicts with other commitments. So don't wait any longer, watch this video and learn how to calculate the next working day in SQL Server!
The end code is (replace "Less Than" with the appropriate symbol):
DROP TABLE IF EXISTS DateTable;
DROP TABLE IF EXISTS Holidays;
CREATE TABLE DateTable
(Dates Date)
INSERT INTO DateTable
SELECT DATEADD(DAY, ROW_NUMBER() OVER(ORDER BY (SELECT NULL)), '2009-12-31')
CREATE TABLE Holidays
(Holiday date)
INSERT INTO Holidays
VALUES ('2023-12-25'),('2023-12-26'),('2024-01-01')
--SELECT *
--FROM DateTable
--WHERE DATEPART(WEEKDAY, Dates) NOT IN (7, 1)
DECLARE @myDate date = '2023-12-24';
With LEADTable AS (
SELECT Dates, LEAD(Dates, 3) OVER(ORDER BY Dates) as ThreeDaysLater
FROM DateTable
WHERE DATEPART(WEEKDAY, Dates) NOT IN (7, 1)
AND Dates NOT IN (SELECT Holiday FROM Holidays)
)
SELECT *
FROM LEADTable
WHERE Dates = (SELECT MAX(Dates) from DateTable
WHERE DATEPART(WEEKDAY, Dates) NOT IN (7, 1)
AND Dates NOT IN (SELECT Holiday FROM Holidays)
AND Dates
Replace with "Less Than"
----
Links to my website are:
Комментарии