SELECT
dt.FullDate
,c.RegistrationGUID
,c.RegistrationNo
,c.FromDate AS CarRegistrationFromDate
,c.ToDate AS CarRegistrationToDate
,p.PolicyNo
,p.FromDate AS PolicyStartDate
,p.ToDate AS PolicyEndDate
--Enrich data by adding in flag which shows whether there was cover
,CASE
WHEN p.PolicyNo IS NULL THEN 'N'
ELSE 'Y'
END AS Cover_YN
FROM CarRegistration c
INNER JOIN DimDate dt
ON dt.FullDate BETWEEN c.FromDate AND c.ToDate
LEFT JOIN CarInsurancePolicy p
ON dt.FullDate BETWEEN p.FromDate AND p.ToDate
AND c.RegistrationGUID = p.RegistrationGUID
;
Created
March 11, 2020 10:47
-
-
Save alcheng10/a489fedbe5346a36547c5773b1eeb873 to your computer and use it in GitHub Desktop.
Daily Date Island Gaps Example
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment