declare @t table (Name char(3) not null, Numbers varchar(6) not null);
insert into @t values ('Abc', ''), ('', '123'), ('Def', ''), ('', '456'),
('', '789'), ('Ghi', ''), ('', '101112');
-- data before the update
select * from @t;
Name Numbers
---- -------
Abc
123
Def
456
789
Ghi
101112
-- join the table with itself on the off-by-one and update it
-- setting the numbers column from the "next" row thus kinda
-- making the column to "pull up" by one row.
;with records as
(
select
Name, Numbers, row_number() over (order by (select null)) N
from @t
)
update a
set Numbers = isnull(b.Numbers, '')
from records a left join records b
on a.N + 1 = b.N;
-- data after the update
select * from @t;
Name Numbers
---- -------
Abc 123
Def 456
789
Ghi 101112
Hope this helps. Oleg
16 People are following this question.