This might work for you:declare @t table (date date, product_code varchar(10), ID_Linea int)insert into @t(date, product_code, ID_Linea) values('01/01/14 ',' BIC01 ',1),('03/01/14 ',' ',2),('01/01/14 ',' ',3 ),('04/01/14 ',' BIC01 ',4 ),('02/01/14 ',' CASH ',5),('05/01/14 ',' ',6),('03/01/14 ',' CASH ',7)update t1set product_code = t2.product_codefrom @t t1cross apply ( select top (1) * from @t t2 where t1.ID_Linea > t2.ID_Linea and t2.product_code <> '' order by t2.ID_Linea desc) t2select * from @t