A multi-user automatically generates numbers in SQLServer

xiaoxiao2021-03-06  54

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

转载请注明原文地址:https://www.9cbs.com/read-82045.html

New Post(0)