Skip to content

Instantly share code, notes, and snippets.

@alcheng10
Created March 11, 2020 10:47
Show Gist options
  • Save alcheng10/a489fedbe5346a36547c5773b1eeb873 to your computer and use it in GitHub Desktop.
Save alcheng10/a489fedbe5346a36547c5773b1eeb873 to your computer and use it in GitHub Desktop.
Daily Date Island Gaps Example

Daily Date Island Gaps Example

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
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment