Auto PLU Codes

create table #x
(id int identity (1,2) not null,
ident char (16))

insert into #x (ident)
select ident from ms

update m
set m.anPLUCode = t.id, m.anPLUCode2 = t.id + 1
from tHE_SetItem m
inner join #x t on m.acIdent = t.ident
go

alter trigger [dbo].[_PLU] on [dbo].[tHE_SetItem]
after insert
as
declare @acIdent char (16)
declare @nNo int
declare btsPoz cursor local fast_forward for
    select acIdent from inserted
open btsPoz
fetch from btsPoz into @acIdent
while @@fetch_status = 0
begin
    set @nNo = (select isnull(max(anPLUCode2),1) from tHE_SetItem)    

    update tHE_SetItem
    set anPLUCode = @nNo+2, anPLUCode2 = @nNo+2
    where acIdent = @acIdent

fetch from btsPoz into @acIdent
end
close btsPoz
deallocate btsPoz