22,209
社区成员
发帖
与我相关
我的任务
分享
if object_id('tempdb..#ID') is not null drop table #ID
create table #ID (採番結果 varchar(100))
insert into #ID exec dbo.SpEstablishRebateGetContractID
create proc SpEstablishRebateGetContractID
as
begin
set nocount on
declare @MaxID int
declare @MaxCD int
declare @CntID int
declare @RtnID int
select @MaxID = isnull(max(創業祭ID),0) from dbo.tblEstablishRebateMstContract with (updlock)
select @CntID = count(1) from dbo.tblEstablishRebateMstContract with (updlock)
if @MaxID <> @CntID
begin
if object_id('tempdb..#ID') is not null
drop table #ID
create table #ID (ID int identity(1,1),Col int )
exec (' insert #ID select top '+@MaxID+' 1 as Col from syscolumns a,syscolumns b')
select @RtnID=isnull(min(ID),0) from #ID
where ID not in ( select 創業祭ID from dbo.tblEstablishRebateMstContract with (updlock))
and ID not in ( select ContractID from dbo.tblEstablishRebateGetContractID with (updlock))
if @RtnID <> 0
begin
select right('00000000'+cast(@RtnID as varchar),8) as 採番結果 ----这个是返回值
insert dbo.tblEstablishRebateGetContractID
select @RtnID,host_name(),getdate()
end
end
if (@MaxID = @CntID) or (@RtnID =0)
begin
select @MaxCD = isnull(max(ContractID),0) from dbo.tblEstablishRebateGetContractID with (updlock)
if @MaxID > @MaxCD
set @RtnID=@MaxID+1
else
set @RtnID=@MaxCD+1
select right('00000000'+cast(@RtnID as varchar),8) as 採番結果 ----这个是返回值
insert dbo.tblEstablishRebateGetContractID
select @RtnID,host_name(),getdate()
end
if object_id('tempdb..#ID') is not null drop table #ID
set nocount off
end
if object_id('tempdb..#GUID') is not null drop table #GUID
create table #GUID (採番結果 varchar(100))
insert into #GUID exec dbo.SpEstablishRebateGetContractID