[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
SELECT COUNT(*) FROM WorkingDays WHERE WorkingDay BETWEEN DATE_CHECK_RECEIVED and DATE_CHECK_DEPOSITED
Open in new window
--Step 1: create the GetAllDates function
IF OBJECT_ID('dbo.GetAllDates','TF') IS NOT NULL
DROP FUNCTION dbo.GetAllDates
CREATE FUNCTION [dbo].[GetAllDates]
@StartDate DATETIME ,
@EndDate DATETIME ,
RETURNS @Dates TABLE
WHILE @StartDate <= @EndDate
IF ( @SkipWeekend = 0 )
OR ( ( @SkipWeekend = 1 ) AND ( DATEPART(WEEKDAY, @StartDate) NOT IN ( 1, 7 ) ) )
INSERT INTO @Dates ( CalendarDate )
SET @StartDate = DATEADD(dd, 1, @StartDate);
--return all days of last week
SELECT * from dbo.GetAllDates(GETDATE()-7, GETDATE(), 0)
--return all WEEK days of last week
SELECT * from dbo.GetAllDates(GETDATE()-7, GETDATE(), 1)
Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.
--Step 3. Query business days
DECLARE @YourDateFrom DATETIME = '2015-03-30'
DECLARE @YourDateFrom DATETIME = '2015-04-16'
WITH CTEDates AS (
SELECT @date1 AS dt
SELECT DATEADD(dd, 1, dt)
FROM CTEDates s
WHERE @YourDateFrom <= @YourDateTo
SELECT COUNT(*) FROM CTEDates WHERE NOT EXISTS (SELECT * FROM dbo.tblHolidays WHERE Holiday = dt)
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.