Afternoon all,
I'm wondering if someone can point me in the right direction, I have a table similar to the one below, I'm trying to write a query to get the number of days worked for a specific employee_id from the startdate and enddate.
Any help would be apreciated.
Thanks
Dave
CREATE TABLE #tempworked
(
id INT PRIMARY KEY,
employee_id INT NOT NULL,
branch_id INT NOT NULL,
startdate DATE NOT NULL,
enddate DATE NOT NULL,
)
INSERT INTO #tempworked
VALUES
(1, 1000, 5000, 2018-06-04, 2018-06-08), -- 5 days mon to fri.
(2, 1000, 5000, 2018-06-12, 2018-06-13), -- 2 days tue & wed.
(3, 1000, 5000, 2018-06-21, 2018-06-26), -- 4 days thurs to tues - excluding weekend.
(4, 1001, 5000, 2018-06-12, 2018-06-12), -- 1 day tues.
(5, 1001, 5000, 2018-07-09, 2018-07-13), -- 2 days mon & tue, thurs fri sat in future
(6, 1001, 5000, 2018-07-24, 2018-07-24) -- 0 days, tue in future
;