求助SQL2005存储过程问题(200)

N

NBAABN

Unregistered / Unconfirmed
GUEST, unregistred user!
存储过程如下:SET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON GOCreate TRIGGER po_kz_tr ON [po_podetails] FOR insertNOT FOR REPLICATION AS Declare @id int(1)Declare @cinvcode nvarchar(2)Declare @poid int(2)Declare @iquantity float(20)Declare @iReceivedQTY float(39)Declare @iappids int(83)Declare @cFlag nvarchar(2)Declare @iMquantity float(20)SET NOCOUNT ONDECLARE apdet1 CURSOR FOR SELECT distinct id,cinvcode,poid,iquantity,iReceivedQTY,iappids FROM inserted OPEN apdet1FETCH NEXT FROM apdet1 INTO @id,@cinvcode,@poid,@iquantity,@iReceivedQTY,@iappidsCLOSE apdet1DEALLOCATE apdet1SET @iMquantity=(select sum(isnull(itopsum,0)) from WhInvContrapose where cwhcode in ('407') and cinvcode=@cinvcode) --取最高库存set @iMquantity=@iMquantity-(select sum(isnull(iquantity,0)) from currentstock where cwhcode in ('407') and cinvcode=@cinvcode) --考虑现存量set @iMquantity=@iMquantity-(select sum(isnull(ps.iquantity,0)) from Po_Podetails ps,po_pomain p where ps.poid=p.poid and isnull(p.ccloser,'')<>'' and dpodate>='2009-01-01' and ps.cinvcode=@cinvcode and id<>@id) --考虑未执行订单If IsNull(@iMquantity,0)>=@iquantitybegin SET NOCOUNT OFF Return --订单量未超过最高库存,采购可以通过endBegin UPDATE Po_Podetails SET iquantity=ISNULL(@iMquantity,0) where id=@id and cinvcode=@cinvcodeEndSET NOCOUNT OFFGOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GO问题:最后得到的结果不正确,iquantity的值总被修改为零,请各位帮忙指出错在哪儿?
 
D

delphi大男孩

Unregistered / Unconfirmed
GUEST, unregistred user!
喜欢delphi的,进qq群delphi世界:23981160
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
2K
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
1K
import
I
顶部