sql存储过程

此存储过程用于将彩票订单状态从未中奖的状态更新为已处理状态。涉及订单表及详情表的更新操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

USE [LotteryData]
GO
/****** 对象:  StoredProcedure [dbo].[sp_ExecuteNoWining]    脚本日期: 07/06/2010 10:05:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:  yb.zhao
-- Create date: 6.12
-- Description: 未中奖
-- =============================================
ALTER PROCEDURE [dbo].[sp_ExecuteNoWining]
    @Status int output,
 @issueid varchar(5),
    @productid int,
    @EngineID int
AS
BEGIN
   begin transaction
   declare @ErrorMsg varchar(500)
   declare @CurrentDate datetime
   set @CurrentDate=getdate()
   set @Status = 0
   /*把详细表里的status为8的数据 订单表里更新为3*/
   update lo set LotteryStatus = 3, WorkflowStatus=1, ModifiedDate=@CurrentDate from lotteryorder lo
   inner join
   (select distinct loy.OrderID from lotteryorder loy inner join lotteryorderdetail lod
   with(nolock) on loy.OrderID = lod.OrderID
   where loy.EngineID = @EngineID and loy.ProductID = @ProductID
   and loy.IssueID = @IssueID and lod.[Status] = 8) A on lo.OrderID = A.OrderID
   if @@error<>0
         begin
           set @ErrorMsg='更新订单时出错'
           set @Status=1
           goto EXIT_ERROR
         end
        
   update lod set status=3 from lotteryorderdetail lod
   inner join
   (select lodt.* from lotteryorderdetail lodt inner join lotteryorder lo
   with(nolock) on lo.OrderID=lodt.OrderID
   where lo.EngineID = @EngineID and lo.ProductID = @ProductID
   and lo.IssueID = @IssueID and lodt.Status = 8) B on lod.OrderDetailID=B.OrderDetailID
   if @@error<>0
         begin
           set @ErrorMsg='更新详细时出错'
           set @Status=1
           goto EXIT_ERROR
         end
   commit transaction
   goto EXIT_END

     EXIT_ERROR:
           rollback transaction
           raiserror(@ErrorMsg,16,1)
  EXIT_END:
END

=========================================================================

1.存储过程的格式

2.update语句

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值