zoukankan      html  css  js  c++  java
  • 存储过程 游标的使用

    项目中有个需求领取的款项过期后自动释放,此处我用了游标来实现,上代码

    USE [QHWCloud]
    GO
    /****** Object:  StoredProcedure [dbo].[pro_Shifang]    Script Date: 05/26/2017 15:04:47 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER   PROCEDURE  [dbo].[pro_Shifang] 
    as
    declare @id int;
    declare @money decimal;
    declare @miid int;
    declare @SumMoney decimal;
    declare @linShimoney decimal;
    declare @Paymoney decimal;
    DECLARE  CUR_GuoQi CURSOR scroll For --创建游标,查询过期数据
        select mr_id,mi_id,mi_receivermoney from t_money_receive t  where t.mi_endtime< GETDATE() and t.mi_state=1  ;
    open CUR_GuoQi;  --打开游标
    begin    
    fetch first from CUR_GuoQi into @id,@miid,@money  --我理解为此处获取游标的第一行
    While @@FETCH_STATUS=0   ---返回被 FETCH 语句执行的最后游标的状态,而不是任何当前被连接打开的游标的状态。
    if(@id!='')
    begin      
        update t_money_receive set  t_money_receive.mi_state=2 where t_money_receive.mr_id=@id; --将该条申请记录状态修改为2 ,释放
        
        set @linShimoney=(select t_money_info.mi_surplusmoney  from t_money_info where t_money_info.mi_id=@miid); --查询可用余额
        
        set @SumMoney=@linShimoney+@money; --重新计算可用余额
        
        set @Paymoney=(select pay_money  from t_money_info where t_money_info.mi_id=@miid) --查询款项的支付金额
        
        
        if(@Paymoney=@SumMoney) --释放后没有其他的领取申请 
         begin
           update t_money_info set t_money_info.mi_surplusmoney=@SumMoney , t_money_info.mi_state=1 where t_money_info.mi_id=@miid; --将领取金额返回到款项可用金额中,并且将状态修改为未领取
         end
         else
            update t_money_info set t_money_info.mi_surplusmoney=@SumMoney, t_money_info.mi_state=2 where t_money_info.mi_id=@miid; --将领取金额返回到款项可用金额中,并且将状态修改为部分领
    fetch next from CUR_GuoQi into @id,@miid,@money   -----提前下一条 信息
      end
    end
    Close CUR_GuoQi;----关闭游标
    deallocate CUR_GuoQi ------删除游标
  • 相关阅读:
    数据库设计 概念结构设计(以权限系统为例)
    sp_addlinkedserver使用方法
    动态页面静态化技术(很不错的教程摘录)
    C#获取硬件序列号
    [转]消息队列关于MSMQ的基础知识
    通过Image对象获取对象的格式
    历史项目的回忆 2008.04.27
    解决Access to Message Queuing system is denied.权限问题
    windows 输入法生成器 导出输入法的mb文件到txt
    [转载]C#版可调节的文字阴影特效
  • 原文地址:https://www.cnblogs.com/zplvpp520/p/6908683.html
Copyright © 2011-2022 走看看