Skip to content

Instantly share code, notes, and snippets.

@oluies
Created December 28, 2011 12:00
Show Gist options
  • Save oluies/1527721 to your computer and use it in GitHub Desktop.
Save oluies/1527721 to your computer and use it in GitHub Desktop.
CROSS JOIN to time-slice history table
-- Active status subscribers
-- Exposes Effective_Date as a pushdown predicate, use this to get only one possible value
REPLACE VIEW Subscriber_Snapshot AS
SELECT Cal.Calendar_Date AS Effective_Date
, Sub.Subscriber_Id
, SSN.Status_Code
FROM Sys_Calendar.Calendar Cal
CROSS JOIN Subscriber Sub
INNER JOIN Sub_Status_History SSH
ON Sub.Subscriber_ID = SSN.Subscriber_Id
AND Cal.Calendar_Date BETWEEN SSH.Effective_Date AND SSH.End_Date
AND SSH.Status_Code = 'Active';
--- ex
--- select ...
--- from Subscriber_Snapshot Sub
--- ,SUB_PHONE_HISTORY ph
--- WHERE Sub.Effective_Date = CURRENT_DATE
--- AND Sub.Subscriber_Id = ph.Subscriber_Id
--- AND Sub.Effective_Date BETWEEN ph.Effective_Date and ph.Expiration_Date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment