I have a scenario where my table has 2 columns and one column has series of dates and another one has some values. Now i need to update the null values with the value corresponding to the most recent date like below.
I can't use LEAD and LAG functions as I am using SQL Server 2008R2.
Sample data is in the below.
DECLARE @Table TABLE
(
Date_D DATE,
Val INT
);
INSERT INTO @Table
(
Date_D,
Val
)
VALUES
('2019-06-15', 2),
('2019-06-16', NULL),
('2019-06-17', NULL),
('2019-06-18', 7),
('2019-06-19', 1),
('2019-06-20', 5),
('2019-06-21', NULL),
('2019-06-22', NULL),
('2019-06-23', NULL),
('2019-06-24', NULL),
('2019-06-25', 9),
('2019-06-26', 5),
('2019-06-27', 3),
('2019-06-28', 4),
('2019-06-29', NULL),
('2019-06-30', 1)
SELECT * FROM @Table

LEADandLAG(not that you actually need them here).