Automatic Generation of numbers by multiple users in sqlserver
If not exists (select * From DBO. sysobjects where id = object_id (n' [indextable] ') and objectproperty (ID, n'isusertable') = 1)
Create Table indextable (ex char (20), num integer)
Go
Create procedure setindex @ ex char (20), @ result char (30) output, @ FMT integer
As
Declare @ num char (10)
Set nocount on
If not exists (select num from indextable where ex = @ ex)
Insert into indextable values (@ ex, 1)
Else
Update indextable set num = num + 1 where ex = @ ex
Select @ num = cast (Num as char (10) from indextable where ex = @ ex
Select @ num = space (@ FMT-len (@ num) + @ num
Select @ num = Replace (@ num, '', '0 ')
Select @ result = rtrim (@ ex) + rtrim (@ num)
Set nocount off
Go
--------
Call in Delphi
Procedure tform1.button1click (Sender: tobject );
Begin
Storedproc1.parambyname ('@ Ex'). asstring: = 'user ';
Storedproc1.parambyname ('@ FMT'). asinteger: = 3;
Storedproc1.execproc;
Showmessage (storedproc1.parambyname ('@ result'). value)
End;
-----------
The @ ex parameter indicates the prefix, @ FMT indicates the number length, and @ result indicates the returned data.
Returns user001