H
hswang
Unregistered / Unconfirmed
GUEST, unregistred user!
我的一个三层程序我已经提交了事务,在Sql Server中执行,数据中表进行了更新,但在程序中执行表没有更新,为什么?多谢相告
附代码如下:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE SJ_scsjsj @SZBH NVARCHAR(50),@Sfks NVARCHAR(50),@sfxt nvarchar(50)
AS
DECLARE @sort INT -- 标示号
--建立事件
BEGIN TRAN
SET NOCOUNT ON
if @sfks=0 or (@sfks=1 and @sfxt=0)
begin
--声明游标
DECLARE CUR_b1yszb_bz CURSOR
FOR SELECT sort FROM t_b1yszb_bz
WHERE szbh=@SZBH order by sort
--打开游标
OPEN CUR_b1yszb_bz
FETCH NEXT FROM CUR_b1yszb_bz INTO @SORT
WHILE @@FETCH_STATUS=0
BEGIN
IF (SELECT COUNT(*) FROM
t_b1yszb_sb WHERE sort=@sort AND szbh=@SZBH)=1
BEGIN
update t_b1yszb_sb set rmb=0.00 where rmb is null and sort=@sort and szbh=@szbh
update t_b1yszb_bz set rmb=0.00 where rmb is null and sort=@sort and szbh=@szbh
UPDATE t_b1yszb_bz SET sjhj=((SELECT rmb FROM t_b1yszb_sb
WHERE sort=@sort AND Szbh=@SZBH)-
(SELECT rmb FROM t_b1yszb_bz
WHERE sort=@sort AND Szbh=@SZBH))
WHERE SORT=@SORT AND Szbh=@SZBH
update t_b1yszb_sb set rmb=null where rmb=0.00 and sort=@sort and szbh=@szbh
update t_b1yszb_bz set rmb=null where rmb=0.00 and sort=@sort and szbh=@szbh
END
FETCH NEXT FROM CUR_b1yszb_bz INTO @SORT
END
--关闭游标
CLOSE CUR_b1yszb_bz
DEALLOCATE CUR_b1yszb_bz
--声明游标
DECLARE CUR_b2gc_bz CURSOR
FOR SELECT sort FROM t_b2gc_bz
WHERE szbh=@SZBH order by sort
--打开游标
OPEN CUR_b2gc_bz
FETCH NEXT FROM CUR_b2gc_bz INTO @SORT
WHILE @@FETCH_STATUS=0
BEGIN
IF (SELECT COUNT(*) FROM
t_b2gc_bz WHERE sort=@sort AND szbh=@SZBH)=1
BEGIN
update t_b2gc_sb set hj=0.00 where hj is null and sort=@sort and szbh=@szbh
update t_b2gc_bz set hj=0.00 where hj is null and sort=@sort and szbh=@szbh
UPDATE t_b2gc_bz SET sjhj=((SELECT hj FROM t_b2gc_sb
WHERE sort=@sort AND Szbh=@SZBH)-
(SELECT hj FROM t_b2gc_bz
WHERE sort=@sort AND Szbh=@SZBH))
WHERE SORT=@SORT AND Szbh=@SZBH
update t_b2gc_sb set hj=null where hj=0.00 and sort=@sort and szbh=@szbh
update t_b2gc_bz set hj=null where hj=0.00 and sort=@sort and szbh=@szbh
END
FETCH NEXT FROM CUR_b2gc_bz INTO @SORT
END
--关闭游标
CLOSE CUR_b2gc_bz
DEALLOCATE CUR_b2gc_bz
--声明游标
DECLARE CUR_b5jqtfy_bz CURSOR
FOR SELECT sort FROM t_b5jqtfy_bz
WHERE szbh=@SZBH order by sort
--打开游标
OPEN CUR_b5jqtfy_bz
FETCH NEXT FROM CUR_b5jqtfy_bz INTO @SORT
WHILE @@FETCH_STATUS=0
BEGIN
IF (SELECT COUNT(*) FROM
t_b5jqtfy_bz WHERE sort=@sort AND szbh=@SZBH)=1
BEGIN
update t_b5jqtfy_sb set hj=0.00 where hj is null and sort=@sort and szbh=@szbh
update t_b5jqtfy_bz set hj=0.00 where hj is null and sort=@sort and szbh=@szbh
UPDATE t_b5jqtfy_bz SET sjhj=((SELECT hj FROM t_b5jqtfy_sb
WHERE sort=@sort AND Szbh=@SZBH)-
(SELECT hj FROM t_b5jqtfy_bz
WHERE sort=@sort AND Szbh=@SZBH))
WHERE SORT=@SORT AND Szbh=@SZBH
update t_b5jqtfy_sb set hj=null where hj=0.00 and sort=@sort and szbh=@szbh
update t_b5jqtfy_bz set hj=null where hj=0.00 and sort=@sort and szbh=@szbh
END
FETCH NEXT FROM CUR_b5jqtfy_bz INTO @SORT
END
--关闭游标
CLOSE CUR_b5jqtfy_bz
DEALLOCATE CUR_b5jqtfy_bz
end
SET NOCOUNT OFF
--提交事件
COMMIT TRAN
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
附代码如下:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE SJ_scsjsj @SZBH NVARCHAR(50),@Sfks NVARCHAR(50),@sfxt nvarchar(50)
AS
DECLARE @sort INT -- 标示号
--建立事件
BEGIN TRAN
SET NOCOUNT ON
if @sfks=0 or (@sfks=1 and @sfxt=0)
begin
--声明游标
DECLARE CUR_b1yszb_bz CURSOR
FOR SELECT sort FROM t_b1yszb_bz
WHERE szbh=@SZBH order by sort
--打开游标
OPEN CUR_b1yszb_bz
FETCH NEXT FROM CUR_b1yszb_bz INTO @SORT
WHILE @@FETCH_STATUS=0
BEGIN
IF (SELECT COUNT(*) FROM
t_b1yszb_sb WHERE sort=@sort AND szbh=@SZBH)=1
BEGIN
update t_b1yszb_sb set rmb=0.00 where rmb is null and sort=@sort and szbh=@szbh
update t_b1yszb_bz set rmb=0.00 where rmb is null and sort=@sort and szbh=@szbh
UPDATE t_b1yszb_bz SET sjhj=((SELECT rmb FROM t_b1yszb_sb
WHERE sort=@sort AND Szbh=@SZBH)-
(SELECT rmb FROM t_b1yszb_bz
WHERE sort=@sort AND Szbh=@SZBH))
WHERE SORT=@SORT AND Szbh=@SZBH
update t_b1yszb_sb set rmb=null where rmb=0.00 and sort=@sort and szbh=@szbh
update t_b1yszb_bz set rmb=null where rmb=0.00 and sort=@sort and szbh=@szbh
END
FETCH NEXT FROM CUR_b1yszb_bz INTO @SORT
END
--关闭游标
CLOSE CUR_b1yszb_bz
DEALLOCATE CUR_b1yszb_bz
--声明游标
DECLARE CUR_b2gc_bz CURSOR
FOR SELECT sort FROM t_b2gc_bz
WHERE szbh=@SZBH order by sort
--打开游标
OPEN CUR_b2gc_bz
FETCH NEXT FROM CUR_b2gc_bz INTO @SORT
WHILE @@FETCH_STATUS=0
BEGIN
IF (SELECT COUNT(*) FROM
t_b2gc_bz WHERE sort=@sort AND szbh=@SZBH)=1
BEGIN
update t_b2gc_sb set hj=0.00 where hj is null and sort=@sort and szbh=@szbh
update t_b2gc_bz set hj=0.00 where hj is null and sort=@sort and szbh=@szbh
UPDATE t_b2gc_bz SET sjhj=((SELECT hj FROM t_b2gc_sb
WHERE sort=@sort AND Szbh=@SZBH)-
(SELECT hj FROM t_b2gc_bz
WHERE sort=@sort AND Szbh=@SZBH))
WHERE SORT=@SORT AND Szbh=@SZBH
update t_b2gc_sb set hj=null where hj=0.00 and sort=@sort and szbh=@szbh
update t_b2gc_bz set hj=null where hj=0.00 and sort=@sort and szbh=@szbh
END
FETCH NEXT FROM CUR_b2gc_bz INTO @SORT
END
--关闭游标
CLOSE CUR_b2gc_bz
DEALLOCATE CUR_b2gc_bz
--声明游标
DECLARE CUR_b5jqtfy_bz CURSOR
FOR SELECT sort FROM t_b5jqtfy_bz
WHERE szbh=@SZBH order by sort
--打开游标
OPEN CUR_b5jqtfy_bz
FETCH NEXT FROM CUR_b5jqtfy_bz INTO @SORT
WHILE @@FETCH_STATUS=0
BEGIN
IF (SELECT COUNT(*) FROM
t_b5jqtfy_bz WHERE sort=@sort AND szbh=@SZBH)=1
BEGIN
update t_b5jqtfy_sb set hj=0.00 where hj is null and sort=@sort and szbh=@szbh
update t_b5jqtfy_bz set hj=0.00 where hj is null and sort=@sort and szbh=@szbh
UPDATE t_b5jqtfy_bz SET sjhj=((SELECT hj FROM t_b5jqtfy_sb
WHERE sort=@sort AND Szbh=@SZBH)-
(SELECT hj FROM t_b5jqtfy_bz
WHERE sort=@sort AND Szbh=@SZBH))
WHERE SORT=@SORT AND Szbh=@SZBH
update t_b5jqtfy_sb set hj=null where hj=0.00 and sort=@sort and szbh=@szbh
update t_b5jqtfy_bz set hj=null where hj=0.00 and sort=@sort and szbh=@szbh
END
FETCH NEXT FROM CUR_b5jqtfy_bz INTO @SORT
END
--关闭游标
CLOSE CUR_b5jqtfy_bz
DEALLOCATE CUR_b5jqtfy_bz
end
SET NOCOUNT OFF
--提交事件
COMMIT TRAN
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO