USE [NLISSST]
GO
/****** Object: StoredProcedure
[SST].[sp_ArbitrationUpdateByID] Script Date: 05/08/2014 10:29:59
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--
=============================================
--
Author: <Author,,高明胜>
-- Create date: <Create
Date,,2014-3-11>
-- Description: <Description,,修改>
--
=============================================
ALTER PROCEDURE
[SST].[sp_ArbitrationUpdateByID]
-- Add the parameters for the stored
procedure here
@Result int
output,--输出结果参数
@ArbitrationID bigint,
@ArbitrationOrderID bigint,
@ArbitrationOrderType int,
@ArbitrationMoney decimal(13,
2),
@ArbitrationRemark varchar(100),
@ArbitrationStatus int,
@ArbitrationUserID bigint,
@ArbitrationTime datetime
as
Set @Result=0
Declare @Error int
Set @Error=0
If
Exists(Select * From SST.tbArbitration Where
ArbitrationID=@ArbitrationID)--存在该项
Begin
if exists(select * from
SST.tbArbitration Where ArbitrationID=@ArbitrationID and
ArbitrationStatus=1)
begin
Set
@Result=2--该订单已经仲裁,不能继续仲裁
end
else
begin
begin
tran
if(@ArbitrationStatus=1) ----更新为已仲,先更新对应订单的金额
begin
declare
@RewardResult int
if(@ArbitrationMoney=0)
set
@RewardResult=0
else
set
@RewardResult=1
if(@ArbitrationOrderType=0)----更新索酬
begin
update
SST.tbRewardOrder
set
RewardOrderMoney=@ArbitrationMoney,
RewardResult=@RewardResult,
RewardOrderStatus=4
where
RewardOrderID=@ArbitrationOrderID
Set
@Error=@Error+@@ERROR--累加错误数量
end
else----更新索酬
begin
if(@ArbitrationOrderType=1)----更新索赔
begin
update
SST.tbPayOrder
set
PayOrderMoney=@ArbitrationMoney,
PayResult=@RewardResult,
PayOrderStatus=4
where
PayOrderID=@ArbitrationOrderID
Set
@Error=@Error+@@ERROR--累加错误数量
end
end
end
Update
SST.tbArbitration Set
ArbitrationOrderID=@ArbitrationOrderID,
ArbitrationOrderType=@ArbitrationOrderType,
ArbitrationMoney=@ArbitrationMoney,
ArbitrationRemark=@ArbitrationRemark,
ArbitrationStatus=@ArbitrationStatus,
ArbitrationUserID=@ArbitrationUserID,
ArbitrationTime=@ArbitrationTime
Where
ArbitrationID=@ArbitrationID
Set
@Error=@Error+@@ERROR--累加错误数量
if(@Error=0)
Begin
Set
@Result=1--成功
commit
tran
End
Else
Begin
Set
@Result=0--失败
rollback
tran
End
end
end
Else
Begin
Set
@Result=-1--失败
End
原文地址:http://www.cnblogs.com/eric-gms/p/3715607.html