请教,为何我下面的存储过程,执行时,报错呢?
错误如下
--------------------------------
消息 266,级别 16,状态 2,过程 up_report_insert_data_103700_26,第 0 行
EXECUTE 后的事务计数指示 BEGIN 和 COMMIT 语句的数目不匹配。上一计数 = 4,当前计数 = 7。
------------------------------
代码如下:
-------------------------------------------------------------------------
create proc up_report_insert_data_103700_26
@p_f_czydm char(4), -- 4位用户代码
@p_f_czymm varchar(20), -- 20位用户密码的密文
@jlxh int, --记录序号
--@fsrq varchar(8), -- 日期
@tzzldm varchar(200), --投资组合代码
@htdm varchar(20), -- 合同代码
@htmc varchar(200), -- 合同名称
@pj_glfl decimal(10, 4) = 0, -- 管理费率
@pj_tgfl decimal(10, 4) = 0, -- 托管费率
@pj_bgfl decimal(10, 4) = 0 -- 保管费率
--@czydm varchar(4) -- 操作员代码
as
set nocount on
if ISNULL(@htdm, '') = ''
begin
select -100 as errorcode, '该合同代码不能为空' as errormsg
return -100
end
if ISNULL(@htmc, '') = ''
begin
select -100 as errorcode, '该合同名称不能为空' as errormsg
return -100
end
--begin tran
if ISNULL(@tzzldm, '') = ''
begin
declare @count int = (select count(tzzldm) from AMV10Base..bill_tzzl)
declare @i int = 1
while @i<=@count
begin
begin tran
--select top 1* from (select top (@count) tzzldm from AMV10Base..bill_tzzl order by tzzldm)a order by tzzldm desc
insert AMV10Base..banking_pact_config (fsrq,tzzldm, htdm, htmc, glfl, tgfl, bgfl, czydm) values ((convert(varchar(10),getdate(),120)), (select top 1* from (select top (@count) tzzldm from AMV10Base..bill_tzzl order by tzzldm)a order by tzzldm desc),@htdm, @htmc ,@pj_glfl ,@pj_tgfl ,@pj_bgfl ,@p_f_czydm)
set @count = @count-1
end
end
--delete from AMV10Base..banking_pact_config
print '11111111'
if ISNULL(@tzzldm, '') != ''
begin tran
begin
insert AMV10Base..banking_pact_config (fsrq,tzzldm, htdm, htmc, glfl, tgfl, bgfl, czydm) values ((convert(varchar(10),getdate(),120)), @tzzldm,@htdm, @htmc ,@pj_glfl ,@pj_tgfl ,@pj_bgfl ,@p_f_czydm)
end
if @@rowcount = 0 or @@error != 0
begin
rollback tran
select -100 as errorcode, '系统错误' + str(@@error) as errormsg
return -100
end
print '22222222'
---------------------------------------******----------------------------------------
declare @czlb varchar(20)
declare @khbs varchar(40)
declare @khbsmc varchar(30)
declare @new_content varchar (200)
declare @bzxx varchar(1000)
select @czlb = 'HTDM_ADD'
select @khbs = @htdm
select @khbsmc = '票据合同代码'
select @new_content = @htdm + ',' + @htmc + ';'
select @bzxx = '增加内容为:' + @new_content
exec nb_add_record_to_lsczlsb @p_f_czydm, @p_f_czymm, @czlb, @khbs, @khbsmc , @bzxx
print '333333333'
-- commit tran
print '4444444444444'
select 0 as errorcode, '增加票据合同成功' as errormsg
--commit tran
print '555555555555'
return 0
go |
|