E
elsss
Unregistered / Unconfirmed
GUEST, unregistred user!
这段代码中家了事务后执行不成功,麻烦那未帮我看一下,可能更游标有关,我看不明白,<br><br>select @store_sc=bb_sc,@store_bm=bb_bm,@dj_pp=bb_pp,@dj_djlx=bb_djlx,@Dj_Num=bb_sl,@Dj_jjje=bb_jjje,@Dj_sjje=bb_sjje,@dj_date=bb_rq from bbcx <br> where bb_djbh=@dj_code<br>---------------------BEGIN TRANSACTION<br><br>--声明游标<br>DECLARE @CrsrVar CURSOR<br>--查询<br>SET @CrsrVar = CURSOR FOR<br> select rk_hh,rk_sl,rk_jj,rk_jjje,rk_sj,rk_sjje,rk_spmc,rk_gg from sprkmx where rk_rkdbh=@dj_code<br><br>--打开<br>OPEN @CrsrVar<br>--读取第一条记录<br>FETCH NEXT FROM @CrsrVar<br>INTO @Com_Code,@DjMx_Num,@Com_CbPrice,@djmx_money, @DjMx_sj, @DjMx_sjje,@Com_name,@com_gg<br>--开始循环<br>WHILE (@@FETCH_STATUS = 0)<br>BEGIN<br> set @cbprice=null<br> --循环单据记录准备操作数据库<br> --写库存总表,先计算加权移动平均价格<br> select @cbprice=(kc_jjje+@djmx_money)/(@djmx_num+kc_sl) from kc<br> where kc_hh=@com_code and kc_sc=@store_sc and kc_bm=@store_bm and kc_pp=@dj_pp and kc_gg=@com_gg<br> if (@cbprice is null) set @cbprice=@Com_CbPrice<br> --select @cbprice<br> --写库存总表<br> update kc set kc_jj=@cbprice,kc_sl=kc_sl+@djmx_num,<br> kc_jjje=kc_jjje+@djmx_money ,kc_sjje=kc_sjje+@djmx_sjje where<br> kc_hh=@com_code and kc_sc=@store_sc and kc_bm=@store_bm and kc_pp=@dj_pp and kc_gg=@com_gg<br> --判断是否写入了,如没有写入就增加新记录<br> if @@rowcount=0<br> begin <br> insert into kc(kc_sc,kc_bm,kc_pp,kc_hh,kc_jj,kc_sl,kc_jjje,kc_sj,kc_sjje,kc_spmc,kc_gg)<br> values(@store_sc,@store_bm,@dj_pp,@com_code,@Com_CbPrice,@djmx_num,@djmx_money,@djmx_sj,@djmx_sjje,@Com_name,@com_gg)<br> end <br> --读取下一条记录<br> FETCH NEXT FROM @CrsrVar<br> INTO @Com_Code,@DjMx_Num,@Com_CbPrice,@djmx_money, @DjMx_sj, @DjMx_sjje,@Com_name,@com_gg<br>END<br>--改变单据的审核标志<br>update bbcx set bb_sh=1,bb_shr=@yg_shr where bb_djbh=@dj_code<br><br>--更新流水库存表<br> select @lskc_chang=max(lskc_chang) from lskc where lskc_sc=@store_sc and lskc_bm=@store_bm and lskc_pp=@dj_pp <br> if (@lskc_chang is null) set @lskc_chang=0<br> select @lskc_jcsl=lskc_kcsl,@lskc_jcjjje=lskc_kcjjje,@lskc_jcsjje=lskc_kcsjje from lskc <br> where lskc_sc=@store_sc and lskc_bm=@store_bm and lskc_pp=@dj_pp and lskc_chang=@lskc_chang<br> if (@lskc_jcsl is null) set @lskc_jcsl=0<br> if (@lskc_jcjjje is null) set @lskc_jcjjje=0<br> if (@lskc_jcsjje is null) set @lskc_jcsjje=0 <br> insert into lskc(lskc_djbh,lskc_djlx,lskc_sl,lskc_jjje,lskc_sjje,lskc_sc,lskc_bm,lskc_pp,lskc_chang,lskc_kcsl,lskc_kcjjje,lskc_kcsjje,lskc_rq)<br> values(@Dj_Code,@dj_djlx,@dj_num,@dj_jjje,@dj_sjje,@store_sc,@store_bm,@dj_pp,@lskc_chang+1,@lskc_jcsl+@dj_num,@lskc_jcjjje+@dj_jjje,@lskc_jcsjje+@dj_sjje,@dj_date)<br>--改变应收付<br>--入库为应付,需要用负数<br>-----update jxc_db_dw set dw_money=dw_money-@dj_money where dw_code=@dw_code and<br>-----class_end=1 and delete_mark=0<br><br><br><br>CLOSE @CrsrVar<br>DEALLOCATE @CrsrVar<br><br><br>IF @@TRANCOUNT > 0<br>BEGIN <br> ROLLBACK TRAN<br>RETURN -1<br>END<br><br>COMMIT TRAN<br>end<br><br><br>GO