SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-09-21 : 04:17:15
|
[code]DECLARE @Sample TABLE ( ID INT, DT DATE, Value INT )SET DATEFORMAT DMYINSERT @Sample ( ID, DT, Value )VALUES (1, '10/02/2010', 11), (1, '11/02/2010', NULL), (1, '12/02/2010', 12), (1, '13/02/2010', NULL), (1, '14/02/2010', 13), (1, '15/02/2010', 15), (2, '20/05/2010', NULL), (2, '21/05/2010', NULL), (2, '22/05/2010', NULL), (2, '23/05/2010', 32), (2, '24/05/2010', 30), (2, '25/05/2010', NULL), (2, '26/05/2010', NULL)SELECT s.ID, s.DT, s.Value, f.Mult, STUFF(g.Mult, 1, 1, '') AS ExplainedFROM @Sample AS sCROSS APPLY ( SELECT EXP(SUM(LOG(x.Value))) FROM @Sample AS x WHERE x.ID = s.ID AND x.DT >= s.DT ) AS f(Mult)CROSS APPLY ( SELECT '*' + ISNULL(CAST(x.Value AS VARCHAR(12)), '1') FROM @Sample AS x WHERE x.ID = s.ID AND x.DT >= s.DT FOR XML PATH('') ) AS g(Mult)[/code] N 56°04'39.26"E 12°55'05.63" |
|
|