/*NAdanie numerow indeksow na podstawie itemtempalte*/

update [wms].[item] 
set itemcode = x.itemcodetemplate + REPLICATE(0,10 - (len(cast(x.rnk as varchar(10))) +  len(x.itemcodetemplate))) + cast(x.rnk as varchar(10)) from 
(select itemid,itemcodetemplate,row_number() over(partition by itemcodetemplate order by adddate) as rnk
from [wms].[item] ) x where x.itemid =  [wms].[item].[itemid] 