就加了这么几句,在运行时没有任何出错信息(就是没有出错信息所以急了)
declare @tmpPeriod varchar(20)
set @tmpPeriod='test' declare @tmpInvCode varchar(20)
declare @tmpOnWay float --在途量(#OnWay.iWay)
declare @tmpPlanReq float --计划需求量(#AAA.iPlanNum)
declare @tmpTotalFactReq float --实际需求总量(sum(PP_PPCDetails.iPQTY))
declare @tmpFactStock float --实际现存量(#Stock.iCStock)
declare @tmpCanUse float --实际可用量(@tmpTotalFactReq-@tmpFactStock)
declare GetInvCode scroll Cursor for select PP_PPCDetails.cInvCode from PP_PPCDetails inner join PP_PPCMain on PP_PPCDetails.cPeriod=PP_PPCMain.cPeriod where PP_PPCDetails.cPeriod=@tmpPeriod and PP_PPCMain.iState<>3 group by PP_PPCDetails.cInvCode open GetInvCode
fetch next from GetInvCode into @tmpInvCode
print cast(@@Fetch_Status as varchar(3))
while @@Fetch_Status=0
begin
select @tmpPlanReq=sum(iPlanNum) from AAA where cInvCode=@tmpInvCode
select @tmpTotalFactReq=sum(PP_PPCDetails.iPQTY) from PP_PPCDetails inner join PP_PPCMain on PP_PPCDetails.cPeriod=PP_PPCMain.cPeriod where PP_PPCMain.iState<>3 and cinvcode=@tmpInvCode
select @tmpOnWay=sum(iWay) from OnWay where cInvCode=@tmpInvCode
select @tmpFactStock=sum(iCStock) from Stock where cinvCode=@tmpInvCode
print 'TotalFactReq='+cast(@tmpTotalFactReq as varchar(10))
print 'FactStock='+ cast(@tmpFactStock as varchar(10))
print 'OnWay='+cast(@tmpOnWay as varchar(10))
set @tmpCanUse=(@tmpFactStock+@tmpOnWay)-@tmpTotalFactReq
print @tmpInvCode+'可用量为(处理前):'+Cast(@tmpCanUse as varchar(10))
if @tmpCanUse<=0
set @tmpCanUse=0
print @tmpInvCode+'可用量为(处理后):'+Cast(@tmpCanUse as varchar(10))
print 'iMQTY='+cast((@tmpPlanReq-@tmpCanUse) as varchar(10))
update Final2 set iMQTY=@tmpPlanReq-@tmpCanUse where cInvCode=@tmpInvCode
print ''
fetch next from GetInvCode into @tmpInvCode
end
close GetInvCode
deallocate GetInvCode
declare @tmpPeriod varchar(20)
set @tmpPeriod='test' declare @tmpInvCode varchar(20)
declare @tmpOnWay float --在途量(#OnWay.iWay)
declare @tmpPlanReq float --计划需求量(#AAA.iPlanNum)
declare @tmpTotalFactReq float --实际需求总量(sum(PP_PPCDetails.iPQTY))
declare @tmpFactStock float --实际现存量(#Stock.iCStock)
declare @tmpCanUse float --实际可用量(@tmpTotalFactReq-@tmpFactStock)
declare GetInvCode scroll Cursor for select PP_PPCDetails.cInvCode from PP_PPCDetails inner join PP_PPCMain on PP_PPCDetails.cPeriod=PP_PPCMain.cPeriod where PP_PPCDetails.cPeriod=@tmpPeriod and PP_PPCMain.iState<>3 group by PP_PPCDetails.cInvCode open GetInvCode
fetch next from GetInvCode into @tmpInvCode
print cast(@@Fetch_Status as varchar(3))
while @@Fetch_Status=0
begin
select @tmpPlanReq=sum(iPlanNum) from AAA where cInvCode=@tmpInvCode
select @tmpTotalFactReq=sum(PP_PPCDetails.iPQTY) from PP_PPCDetails inner join PP_PPCMain on PP_PPCDetails.cPeriod=PP_PPCMain.cPeriod where PP_PPCMain.iState<>3 and cinvcode=@tmpInvCode
select @tmpOnWay=sum(iWay) from OnWay where cInvCode=@tmpInvCode
select @tmpFactStock=sum(iCStock) from Stock where cinvCode=@tmpInvCode
print 'TotalFactReq='+cast(@tmpTotalFactReq as varchar(10))
print 'FactStock='+ cast(@tmpFactStock as varchar(10))
print 'OnWay='+cast(@tmpOnWay as varchar(10))
set @tmpCanUse=(@tmpFactStock+@tmpOnWay)-@tmpTotalFactReq
print @tmpInvCode+'可用量为(处理前):'+Cast(@tmpCanUse as varchar(10))
if @tmpCanUse<=0
set @tmpCanUse=0
print @tmpInvCode+'可用量为(处理后):'+Cast(@tmpCanUse as varchar(10))
print 'iMQTY='+cast((@tmpPlanReq-@tmpCanUse) as varchar(10))
update Final2 set iMQTY=@tmpPlanReq-@tmpCanUse where cInvCode=@tmpInvCode
print ''
fetch next from GetInvCode into @tmpInvCode
end
close GetInvCode
deallocate GetInvCode
declare @tmpPeriod varchar(20)
set @tmpPeriod='test' declare @tmpInvCode varchar(20)
declare @tmpOnWay float --在途量(#OnWay.iWay)
declare @tmpPlanReq float --计划需求量(#AAA.iPlanNum)
declare @tmpTotalFactReq float --实际需求总量(sum(PP_PPCDetails.iPQTY))
declare @tmpFactStock float --实际现存量(#Stock.iCStock)
declare @tmpCanUse float --实际可用量(@tmpTotalFactReq-@tmpFactStock)
declare GetInvCode scroll Cursor for select PP_PPCDetails.cInvCode from PP_PPCDetails inner join PP_PPCMain on PP_PPCDetails.cPeriod=PP_PPCMain.cPeriod where PP_PPCDetails.cPeriod=@tmpPeriod and PP_PPCMain.iState<>3 group by PP_PPCDetails.cInvCode open GetInvCode
fetch next from GetInvCode into @tmpInvCode
print cast(@@Fetch_Status as varchar(3))
while @@Fetch_Status=0
begin
select @tmpPlanReq=sum(iPlanNum) from AAA where cInvCode=@tmpInvCode
select @tmpTotalFactReq=sum(PP_PPCDetails.iPQTY) from PP_PPCDetails inner join PP_PPCMain on PP_PPCDetails.cPeriod=PP_PPCMain.cPeriod where PP_PPCMain.iState<>3 and cinvcode=@tmpInvCode
select @tmpOnWay=sum(iWay) from OnWay where cInvCode=@tmpInvCode
select @tmpFactStock=sum(iCStock) from Stock where cinvCode=@tmpInvCode
print 'TotalFactReq='+cast(@tmpTotalFactReq as varchar(10))
print 'FactStock='+ cast(@tmpFactStock as varchar(10))
print 'OnWay='+cast(@tmpOnWay as varchar(10))
set @tmpCanUse=(@tmpFactStock+@tmpOnWay)-@tmpTotalFactReq
print @tmpInvCode+'可用量为(处理前):'+Cast(@tmpCanUse as varchar(10))
if @tmpCanUse<=0
set @tmpCanUse=0
print @tmpInvCode+'可用量为(处理后):'+Cast(@tmpCanUse as varchar(10))
print 'iMQTY='+cast((@tmpPlanReq-@tmpCanUse) as varchar(10))
update Final2 set iMQTY=@tmpPlanReq-@tmpCanUse where cInvCode=@tmpInvCode
print ''
fetch next from GetInvCode into @tmpInvCode
end
close GetInvCode
deallocate GetInvCode
declare GetInvCode scroll Cursor for select PP_PPCDetails.cInvCode from PP_PPCDetails inner join PP_PPCMain on PP_PPCDetails.cPeriod=PP_PPCMain.cPeriod where PP_PPCDetails.cPeriod=@tmpPeriod and PP_PPCMain.iState<>3 group by PP_PPCDetails.cInvCode open GetInvCode