Create Procedure GerarId1 @indice varchar(20), @qtdade int, @codigo int output AS UPDATE Tab00c Set @codigo = ultimo = ultimo + @qtdade where indice=@indice If @@rowcount = 0 Begin insert into tab00c values (@indice,@qtdade) set @codigo = @qtdade End set @codigo = @codigo - (@qtdade - 1) GOI added a new parameter (qtdade) that is used to add more than 1 record each time. For example:
codigo =0 SQLExec(1,"EXEC GerarId1 'MyCounter',5, ?@codigo")After run this code, codigo is equal 1 and the last ID is 5 (in table counter). In my application, I know that I can use the codes 1, 2, 3, 4 and 5. After that, if you need to generate 3 new codes, run again:
codigo =0 SQLExec(1,"EXEC GerarId1 'MyCounter',3, ?@codigo")Then you have: Codigo = 6 and then you can use 6, 7 and 8.