Below is two table for two projects.
STS is start time in Hour, ETS is End Time in Hour,
CREATE TABLE #V(NAME VARCHAR(100), STS INTEGER, ETS INTEGER,Stat VARCHAR(10))
CREATE TABLE #E(NAME VARCHAR(100), STS INTEGER, ETS INTEGER,Stat VARCHAR(10))
INSERT INTO #V VALUES('ABC',1,5,'Busy')
INSERT INTO #V VALUES('ABC',7,10,'Ready')
INSERT INTO #E VALUES('ABC',1,3,'Not Ready')
INSERT INTO #E VALUES('ABC',3,5,'Ready')
INSERT INTO #E VALUES('ABC',5,8,'Not Ready')
INSERT INTO #E VALUES('ABC',9,12,'Busy')
Eg: ABC work from 1 pm to 5 pm with status Busy.
As you see the different type of overlapping STS and ETS,
I want a combine result with breakup of STS and ETS
Output:
ABC, 1, 3, Busy, TableV
ABC, 1, 3, Not Ready, TableE
ABC, 3, 5, Busy, TableV
ABC, 3, 5, Ready, TableE
ABC, 5, 7, NULL, TableV
ABC, 5, 7, Not Ready, TableE
ABC, 7, 8, Ready, TableV
ABC, 7, 8, Not Ready, TableE
ABC, 8, 9, Ready, TableV
ABC, 8, 9, Busy, TableE
ABC, 9,10, Ready, TableV
ABC, 9,10, Busy, TableE
ABC, 10,12, NULL, TableV
ABC, 10,12, Busy, TableE
Thanks in Advance