--Dla pojedynczego

 
declare @itemcodeLengthMask int = 10	 --<< wypelnij
declare @itemcodeMask varchar(10) = 'DE'  --<< wypelnij
declare @currentNR int 


select @currentNR = max(cast(substring(itemcode ,3,@itemcodeLengthMask) as int))  from wms.item
where itemcode like @itemcodeMask +'%'	  and len(itemcode) =@itemcodeLengthMask
print	@currentNR
 
if not exists (  select  1 from [common].[Numerator]	  where	 remoteSource='item' and param1 = @itemcodemask) 
	insert into   [common].[Numerator]	 (param1,numerator, remoteSource)
	select  @itemcodeMask,  isnull(@currentNR,1),'item' 

 