SQLServer中一个多用户自动生成编号的过程

王朝delphi·作者佚名  2006-01-29
窄屏简体版  字體: |||超大  

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

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

--------

在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;

-----------

参数@ex表示前缀,@fmt表示数字长度,@result表示返回数据

返回User001

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航