DECLARE @Contracts TABLE (OperatorId INT, Operator VARCHAR(20), dDate DATETIME, ContractNo VARCHAR(20))
INSERT INTO @Contracts
SELECT
5,'Nigel Tuffnell','2019-12-10','15741'
UNION ALL
SELECT
5,'Nigel Tuffnell','2019-12-10','3/15747'
UNION ALL
SELECT
5,'Nigel Tuffnell','2019-12-11','3/15747'
DECLARE @Dates TABLE (dDate DATETIME)
INSERT INTO @Dates
SELECT
'2019-12-09'
UNION ALL
SELECT
'2019-12-10'
UNION ALL
SELECT
'2019-12-11'
UNION ALL
SELECT
'2019-12-12'
UNION ALL
SELECT
'2019-12-13'
UNION ALL
SELECT
'2019-12-14'
UNION ALL
SELECT
'2019-12-15'
I can achieve the 'current result' but not the 'desired result', i.e. i want to remove unecessary rows, e.g. NULLS and, in this example, row 4 in the first result set should be merged with row 3. Hope this makes sense.