declare @T table
(
ID int,
Batch char(2),
New_Batch char(2)
)
insert into @T values
(1, '01', NULL),
(2, '01', NULL),
(3, '02', NULL),
(4, '02', NULL),
(5, '02', NULL),
(6, '03', NULL),
(7, '04', NULL),
(8, '05', NULL)
;with C as
(
select T1.New_Batch,
dense_rank() over(order by -T2.ID desc, T1.Batch) as rn
from @T as T1
left outer join (select Batch, ID
from @T
where ID in (3, 8)) as T2
on T1.Batch = T2.Batch
)
update C
set New_Batch = right(100+rn, 2)
select *
from @T
order by ID
Попробуйте здесь: http://data.stackexchange.com/stackoverflow/q/113031/