首页 > 开发 > 综合 > 正文

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

2024-07-21 02:11:59
字体:
来源:转载
供稿:网友

商业源码热门下载www.html.org.cn

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 [email protected] )
   insert into indextable values(@ex,1)
  else
   update indextable set num=num+1 where [email protected]
  select @num=cast(num as char(10)) from indextable where [email protected]
  select @num=space(@fmt-len(@num))[email protected]
  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

 

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表