declare @alo as table(x int, y float);
insert into @alo (x,y) values (1,10);
insert into @alo (x,y) values (2,20);
insert into @alo (x,y) values (3,null);
insert into @alo (x,y) values (4,null);
insert into @alo (x,y) values (5,null);
insert into @alo (x,y) values (6,30);
SELECT this.x as [X], isnull(this.y,
(
SELECT CASE WHEN next.x IS NULL THEN prev.y
WHEN prev.x IS NULL THEN next.y
WHEN next.x = prev.x THEN prev.y
ELSE prev.y + ( (next.y - prev.y) * (this.x - prev.x) / (next.x - prev.x) )
END
FROM
( SELECT TOP 1 X, Y FROM @alo WHERE x <= this.x and y is not null ORDER BY x DESC ) AS prev
CROSS JOIN
( SELECT TOP 1 X, Y FROM @alo WHERE x >= this.x and y is not null ORDER BY x ASC ) AS next
)) as [Y]
FROM @alo this order by this.x ASC