zoukankan      html  css  js  c++  java
  • sqlserver 脚本 多条记录遍历

    临时表方式实现多条记录遍历

    declare @oper_cart_item_id bigint;
     declare @oper_cart_id bigint;
     declare @the_last_changed_date datetime;
     declare @oper_cust_id int;
     
     
         select * , 0 as flag into #shoppingcart_temp from deleted;
        while exists (select top 1 1 from #shoppingcart_temp t where t.flag = 0 )
        begin
      
        select top 1 
        @oper_cart_item_id = cart_item_id,@oper_cart_id = cart_id,
        @oper_cust_id = cust_id,@the_last_changed_date = last_changed_date
        from  #shoppingcart_temp where flag = 0 ;
    
        if @oper_cart_item_id is not null and @oper_cart_item_id <> 0 and left(@oper_cart_id,1) = '8'
        begin
           exec proc_sqlser_insertqueue @oper_cart_id,@oper_cart_item_id, @the_last_changed_date, @oper_cust_id, '3';
        end
      
        update  #shoppingcart_temp  set  flag = 1 where cart_item_id = @oper_cart_item_id
      end

    游标方式实现多条记录遍历

    declare @oper_cart_item_id bigint;
     declare @oper_cart_id bigint;
     declare @the_last_changed_date datetime;
     declare @oper_cust_id int;
     
        declare shoppingcart_cursor cursor for select cart_item_id,cart_id,cust_id,last_changed_date from deleted;
     
        open shoppingcart_cursor
       
        fetch next from shoppingcart_cursor into @oper_cart_item_id,@oper_cart_id, @oper_cust_id,@the_last_changed_date
       
        while (@@fetch_status=0)
        begin
     
            if @oper_cart_item_id is not null and @oper_cart_item_id <> 0 and left(@oper_cart_id,1) = '8'
            begin
               exec proc_sqlser_insertqueue @oper_cart_id,@oper_cart_item_id, @the_last_changed_date, @oper_cust_id, '3';
            end
            fetch next from shoppingcart_cursor into @oper_cart_item_id,@oper_cart_id, @oper_cust_id,@the_last_changed_date
        end
        close shoppingcart_cursor
        DEALLOCATE shoppingcart_cursor
  • 相关阅读:
    Java集合知识点小结
    集合类说明及区别
    微信翻译机器人实战
    细说:域名与SEO存在什么关系
    我为PHP摇旗呐喊!
    每个程序员都该知道的10大编码原则
    浏览器加载模式:window.onload和$(document).ready()
    修改Mysql编码集
    java实现LIS算法,出操队形问题
    [笔记]: 前向星 标签: 数据结构存储 2017-05-25 09:13 35人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/olmlo/p/3757802.html
Copyright © 2011-2022 走看看