I am trying to Capture historical changes in a fact table to be used as a basis for a type 2 SCD. I would like to see only the changes in of the PCT column by employee id and a continous stream of time >=2013-01-01. Can someone assist in the t-sql?
SELECT DISTINCT e.EmployeeID, COALESCE(e.Pct,0) Pct, c.FirstDateOfMonth, c.LastDateOfMonth FROM Testdb.dbo.Calendar c LEFT OUTER JOIN Testdb.dbo.T_EMP_PRODUCTIVITY e ON c.CalendarDate = CAST(LEFT(e.PostPeriod,4) + '-'+ RIGHT(e.PostPeriod,2)+ '-01' as datetime) WHERE c.LastDateOfMonth between' 2013-01-01' and getdate()Employee 8 Below should have .80 from 2013-01-01 through 2014-01-31, then from beginning 2014-02-01 to 2015-02-28 it should be .5, then from 2015-03-01 to 2015-03-31 it should be .23 , then back to .5 after 2015-04-01.