Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Record ID generator question
Message
 
À
20/09/2002 17:43:25
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
00605839
Message ID:
01163493
Vues:
21
Hi,

Sorry for reply a past thread, but I was searching for some code like that in UT. Using your idea, I wrote this code:
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)
GO
I added a new parameter (qtdade) that is used to add more than 1 record each time. For example:
If you have to generate 5 records, you can call this SP like this:
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.

Sorry for my bad english, but my point is trying to help other users!.

By the way, I'm *really* SQL novate user! If I'm doing some thing wrong, please tell me!

Bye!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Rodolfo Duarte
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform