码迷,mamicode.com
首页 > 其他好文 > 详细

存储过程更新

时间:2014-05-08 18:50:01      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:des   int   c   2014   com   set   

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

 

存储过程更新,布布扣,bubuko.com

存储过程更新

标签:des   int   c   2014   com   set   

原文地址:http://www.cnblogs.com/eric-gms/p/3715607.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!