How can I fill the null values with the values below these null values?
Example, I have a table like this:
Mat Name
123 Jerry
Null Mary
Null Sam
45
If you are able to add an ID
column to your table (if you don't have one already) this query should work
declare @tbl as table (
id int
,mat int
,name varchar(15)
)
insert into @tbl values (1,123, 'Jerry')
insert into @tbl values (2,NULL, 'Marry')
insert into @tbl values (3,NULL, 'Sam')
insert into @tbl values (4,456, 'Matt')
insert into @tbl values (5,NULL, 'Harry')
insert into @tbl values (6,NULL, 'Jin')
SELECT
id
,CASE WHEN
mat IS NULL THEN
(SELECT TOP 1 mat FROM @tbl WHERE id