首页 新闻 搜索 专区 学院

急!COMMIT TRANSACTION 请求没有对应的 BEGIN TRANSACTION。 COMMIT TRANSACTION 请求没有对应的 BEGIN TR

0
悬赏园豆:50 [已解决问题] 解决于 2014-12-10 17:29

create procedure pd_InsertProduct
(
@Name varchar(100),
@Author varchar(30),
@price float,
@DctPrice float,
@PubDate datetime,
@Stock int,
@BusinesserNO varchar(100),
@Discount int,
@Binding varchar(50),
@HevayRecomment varchar(250),
@LanguageType varchar(100),
@Revision int,
@PrintingDate datetime,
@PublishCompany varchar(150),
@Impression int,
@EditorRecommentd varchar(max),
@InstroContent varchar(max),
@Derectory varchar(max),
@MediaDiscuss varchar(max),
@WorderfulContent varchar(max),
@PdTypeID int,
@PicNO varchar(100),
@AttrNameList varchar(250),
@AttrValueList varchar(max)
)
as
declare @id int
begin tran
insert into dbo.Product (Name,Author,Price,DctPrice,PubDate,Stock,ClickNumber,BusinesserNO,Discount,Binding,HevayRecomment,LanguageType,Revision,PrintingDate,PublishCompany,Impression,EditorRecommentd,InstroContent,Derectory,MediaDiscuss,WorderfulContent,PdTypeID,PicNO)
values
(@Name,@Author,@price,@DctPrice,@PubDate,@Stock,default,@BusinesserNO,@Discount,@Binding,@HevayRecomment,@LanguageType,@Revision,@PrintingDate,@PublishCompany,@Impression,@EditorRecommentd,@InstroContent,@Derectory,@MediaDiscuss,@WorderfulContent,@PdTypeID,@PicNO)
select @id=@@IDENTITY
if(@@error!=0)
rollback tran
else
declare @AttrName varchar(250)
declare @AttrValue varchar(250)
declare @AttrNamelog varchar(500)
declare @AttrValuelog varchar(500)
declare @Number int
declare @id2 int
declare @number2 int
set @number=charindex(',',@AttrNameList)
set @AttrName=left(@AttrNameList,@number-1)
set @AttrNamelog=right(@AttrNameList,len(@AttrNameList)-@number)
set @number2=charindex(',',@AttrValueList)
set @AttrValue=left(@AttrValueList,@number2)
set @AttrValuelog=right(@AttrValueList,len(@AttrValueList)-@number2)
while(@number>0)
begin
insert into ProductAtrr(FName,ProductID) values (@AttrName,@id)
set @id2=@@identity
if(@@error!=0)
rollback tran
else
begin
set @number=charindex(',',@AttrNamelog)
set @AttrName=left(@AttrNamelog,@number-1)
set @AttrNamelog=right(@AttrNamelog,len(@AttrNamelog)-@number)
insert into dbo.AtrrVal (Description,AttrID) values (@AttrValue,@id2)
end
if(@@error!=0)
begin
rollback tran
end
else
begin
set @number2=charindex(',',@AttrValuelog)
set @AttrValue=left(@AttrValuelog,@number2)
set @AttrValuelog=right(@AttrValuelog,len(@AttrValuelog)-@number2)
end
if(@@error!=0)
rollback tran
else
commit tran
end
go

星休的主页 星休 | 初学一级 | 园豆:4
提问于:2014-12-02 02:29
< >
分享
最佳答案
1

实际上tran只有一个,你在上面rollback过了,最后commit当然没有了。每个if都会去判断执行的。rollback不会中断程序。

收获园豆:50
幻天芒 | 高人七级 |园豆:36652 | 2014-12-02 08:50
其他回答(1)
0

加return就可以了

星休 | 园豆:4 (初学一级) | 2014-12-03 17:04
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册