关于存储过程中的事务(应该是简单问题)(50分)

E

elsss

Unregistered / Unconfirmed
GUEST, unregistred user!
这段代码中家了事务后执行不成功,麻烦那未帮我看一下,可能更游标有关,我看不明白,<br><br>select &nbsp;@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> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;where bb_djbh=@dj_code<br>---------------------BEGIN TRANSACTION<br><br>--声明游标<br>DECLARE @CrsrVar CURSOR<br>--查询<br>SET @CrsrVar = CURSOR FOR<br> select &nbsp;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> &nbsp;set @cbprice=null<br> &nbsp;--循环单据记录准备操作数据库<br> &nbsp; &nbsp; --写库存总表,先计算加权移动平均价格<br> &nbsp; &nbsp;select @cbprice=(kc_jjje+@djmx_money)/(@djmx_num+kc_sl) from kc<br> &nbsp; &nbsp;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> &nbsp; &nbsp;if (@cbprice is null) set @cbprice=@Com_CbPrice<br> &nbsp; &nbsp;--select @cbprice<br> &nbsp; &nbsp;--写库存总表<br> &nbsp; &nbsp;update kc set kc_jj=@cbprice,kc_sl=kc_sl+@djmx_num,<br> &nbsp; &nbsp;kc_jjje=kc_jjje+@djmx_money ,kc_sjje=kc_sjje+@djmx_sjje where<br> &nbsp; &nbsp;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> &nbsp; &nbsp;--判断是否写入了,如没有写入就增加新记录<br> &nbsp; &nbsp;if @@rowcount=0<br> &nbsp; &nbsp;begin &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; 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> &nbsp; &nbsp; &nbsp; values(@store_sc,@store_bm,@dj_pp,@com_code,@Com_CbPrice,@djmx_num,@djmx_money,@djmx_sj,@djmx_sjje,@Com_name,@com_gg)<br> &nbsp; &nbsp;end &nbsp; <br> &nbsp;--读取下一条记录<br> &nbsp;FETCH NEXT FROM @CrsrVar<br> &nbsp;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> &nbsp; select @lskc_chang=max(lskc_chang) from lskc where lskc_sc=@store_sc and lskc_bm=@store_bm and lskc_pp=@dj_pp <br> &nbsp; &nbsp; if (@lskc_chang is null) set @lskc_chang=0<br> &nbsp; select @lskc_jcsl=lskc_kcsl,@lskc_jcjjje=lskc_kcjjje,@lskc_jcsjje=lskc_kcsjje from lskc <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where lskc_sc=@store_sc and lskc_bm=@store_bm and lskc_pp=@dj_pp and lskc_chang=@lskc_chang<br> &nbsp; &nbsp; &nbsp; &nbsp; if (@lskc_jcsl is null) set @lskc_jcsl=0<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (@lskc_jcjjje is null) set @lskc_jcjjje=0<br> &nbsp; &nbsp; &nbsp; &nbsp; if (@lskc_jcsjje is null) set @lskc_jcsjje=0 &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; 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> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 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 &gt; 0<br>BEGIN &nbsp;<br> ROLLBACK TRAN<br>RETURN -1<br>END<br><br>COMMIT TRAN<br>end<br><br><br>GO
 
事务也需要定义,没看到你定义事务的语句?
 
是BEGIN TRANSACTION<br>这句么,我执行的时候有,上面是复制的时候注释掉的
 
我把IF @@TRANCOUNT &gt; 0 换成 &nbsp;IF @@ERROR &lt;&gt; 0 &nbsp;就行了,谁能给我讲一下么,然后结萜<br> 它们在过程执行完整性上有什么区别
 
多人接受答案了。
 
顶部