server|sqlserver| process
The process of automatically generating a number in SQL Server for multiple users
If not EXISTS (SELECT * from dbo.sysobjects WHERE id = object_id (n ' [indextable] ') and OBJECTPROPERTY (ID, n ' isusertable ') = 1)
CREATE TABLE indextable (Ex char (), num integer)
Go
CREATE PROCEDURE Setindex @Ex char (), @result char 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) 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 parameter @ex represents the prefix, @fmt represents the number length, @result represents the return data
Back to User001