If you use the code below you will see that obsvalue is not 106 for 2010-01-08 and 2010-01-09. Can anyone help me out..I started out ok but not entirely. What can I do to fix this small issue? The result should show a replacement of null values with previous non-null value.Thanks in advance.create table test(obsdate datetime,obsvalue int)insert into test(obsdate, obsvalue)select '2010-01-01', 100unionselect '2010-01-02', 101unionselect '2010-01-03', nullunionselect '2010-01-04', nullunionselect '2010-01-05', 104unionselect '2010-01-06', 105unionselect '2010-01-07', 106unionselect '2010-01-08', nullunionselect '2010-01-09', nullunionselect '2010-01-10', 109declare @from datetimedeclare @to datetimedeclare @minDate datetimedeclare @latestKnownObsValue int--set @from = '2010-01-03'--set @to = '2010-01-05'--set @from = '2010-01-01' --set @to = '2010-01-06' set @from = '2010-01-01' set @to = '2010-01-10' select * from test--for this result, find the previous non-null value replace with the null valueselect obsdate, obsvalue from testwhere obsdate between @from and @toselect @minDate=min(obsdate) from test where obsvalue is nulland obsdate between @from and @to select @latestKnownObsValue=max(obsvalue)from testwhere obsdate < @minDateselect obsdate, isnull(obsvalue ,@latestKnownObsValue) as obsvaluefrom testwhere obsdate between @from and @to