If not exists (select * from dbo.sysobjects where id = Object_id (n '[indextable]') And ObjectProperty (ID, n'uSERTABLE ') = 1) CREATE TABLE INDEXTABLE (EX Char (20), NUM Integer
Go
create procedure SetIndex @Ex char (20), @ result char (30) output, @ Fmt integeras 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 offgo
------------
Call in Delphi
procedure TForm1.Button1Click (Sender: TObject); begin StoredProc1.ParamByName ( '@ Ex') AsString:. = 'User'; StoredProc1.ParamByName ( '@ fmt') AsInteger:. = 3; StoredProc1.ExecProc; showmessage (StoredProc1 .Pambyname ('@ result'). Value) end;
----------- Parameter @EX represents the prefix, @ fmt represents the number length, @ result indicates that the return data returns USER001