752
社区成员
发帖
与我相关
我的任务
分享
ALTER procedure p_getmaxid(@tablename varchar(50),@preface varchar(50),@bh varchar(50) output)
as
begin tran
declare @i int
declare @curdate char(8)
select @curdate=replace(convert(char(11),getdate(),121),'-','')
update tablemax with(rowlock) set
@i=case when currentdate=@curdate then maxid+1 else 1 end,
currentdate = @curdate,
@bh= preface+@curdate+right(power(10,len)+@i,len),
maxid=@i
where preface = @preface and tablename=@tablename
commit tran
string bh,tablename,preface
tablename="bloodapp"
preface="app"
DECLARE pgetmaxid PROCEDURE FOR p_getmaxid
@tablename=:tablename,
@preface=:preface,
@bh=:bh output
using sqlca;
execute pgetmaxid;
if sqlca.sqlcode<>0 then
close pgetmaxid;
return
else
FETCH pgetmaxid INTO :bh;
if sqlca.sqlcode<>0 then
close pgetmaxid;
return
end if
end if