I managed to write some code that doesn't use a cursor, so hooray for performance 🙂
SELECT
ID= tmp.ID
,Value= t3.[Value]
FROM
(SELECT t1.[ID]
,MaxID = MAX(t2.ID)
FROM[dbo].[Test] t1
INNER JOIN[dbo].[Test] t2 ON [t1].[ID] >= [t2].[ID] AND t2.[Value] IS NOT NULL
GROUP BY t1.[ID]) tmp
INNER JOIN [dbo].[Test] t3 ON tmp.[MaxID] = t3.[ID]
Please read the link in my signature on how to post questions and sample data. It will make the life of people who are trying to answer your question easier.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP