Need to edge out the competition for your dream job? Train for certifications today.
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)
This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.
--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.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment