declare @num int, @RCnt int
select @RCnt = count(*) from  [dbo].[T_PLAN_REQUEST]

exec @num =  sp_GenerateNumber 540, 'Number', @RCnt 

select  (ROW_NUMBER() over (Order by t3.[Year], t2.Mo) + @num) as Number, t1.PlanID into #tmp
from T_PLAN_REQUEST t1 
join T_PLAN t2 on t2.PlanID = t1.PlanID
join T_PLAN_PERIOD t3 on t3.PlanPeriodID = t2.PlanPeriod

update t1 set  t1.Number = t2.Number
from T_PLAN_REQUEST t1
join #tmp t2 on t2.PlanID = t1.PlanID


drop table #tmp
