当前位置:主页>Delphi教程>文章内容
SQLServer中一个多用户自动生成编号的过程
来源: 作者: 发布时间:2007-04-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


 
上一篇:让你的DBGridEh的Column自动适应宽度   下一篇:入手自制软件背单词
 
  相关文章
·让你的DBGridEh的Column自动适应宽度
·入手自制软件背单词
·Delphi的拨号连接类
·动态SQL语句在SQLServer中非固定行的转
·对“网页内容查询控制”主题所得(下载
·来自SVG的灵感
·SQLServer和Oracle的常用函数对比
·实现StatusBar的Flat风格
·软件注册加密技术
·SQLServer中按某字段排列名次
·ComboBox的DataValue值
·Delphi使用方法
 
【关闭窗口】
推荐本站资源
最新文章