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

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) = ''
begin
exec proc_sqlser_insertqueue @oper_cart_id,@oper_cart_item_id, @the_last_changed_date, @oper_cust_id, '';
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) = ''
begin
exec proc_sqlser_insertqueue @oper_cart_id,@oper_cart_item_id, @the_last_changed_date, @oper_cust_id, '';
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

sqlserver 脚本 多条记录遍历的更多相关文章

  1. SqlServer插入1000条记录

    1.想在SqlServer中插入指定数量的测试记录怎么办? 2.解决: DECLARE @var INT ) BEGIN INSERT INTO test (Name) VALUES (convert ...

  2. 分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)

    分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...

  3. (转)分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)

    分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...

  4. 从SQLSERVER/MYSQL数据库中随机取一条或者N条记录

    从SQLSERVER/MYSQL数据库中随机取一条或者N条记录 很多人都知道使用rand()函数但是怎麽使用可能不是每个人都知道 建立测试表 USE [sss] GO ,NAME ) DEFAULT ...

  5. SQLServer 分组查询相邻两条记录的时间差

    原文:SQLServer 分组查询相邻两条记录的时间差 首先,我们通过数据库中表的两条记录来引出问题,如下图 以上为一个记录操作记录的表数据.OrderID为自增长列,后面依次为操作类型,操作时间,操 ...

  6. sqlserver -- 学习笔记(七)获取同组数据的前两条记录

    不啰嗦,直接上图,大概实现效果如下: 有上面这样一份数据,将他们按照userAccount和submitTime进行分组,然后提前每组数据的前两条记录 提取后数据如下: 实现的SQL如下: selec ...

  7. SQLServer 触发器 同时插入多条记录有关问题

    由于 SQL Server 的触发器, 没有 FOR EACH ROW (ORACL中有)的选项, 有时候不正确的使用 inserted 与deleted 可能会有点麻烦. 下面来一个简单的例子 -- ...

  8. sqlserver查询数据表中每个类别最新的一条记录

    表tariff_info, 原始数据: 想要的结果:以start_time时间倒序排序, 以code分类, 查询每一类最新的一条记录 sql: SELECT a.* FROM TARIFF_INFO ...

  9. 分享一个SQLSERVER脚本

    原文:分享一个SQLSERVER脚本 分享一个SQLSERVER脚本 很多时候我们都需要计算数据库中各个表的数据量很每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tablespac ...

随机推荐

  1. mysql主从复制、操作语句

    授权 grant replication slave on *.* to slave@192.168.10.64 identified by "123456" 登录测试 mysql ...

  2. Laravel 5.2 四、.env 文件与模型操作

    一..env文件 .env 文件是应用的环境配置文件,在配置应用参数.数据库连接.缓存处理时都会使用这个文件. // 应用相关参数 APP_ENV=local APP_DEBUG=true //应用调 ...

  3. Oracle 表连接方式

    1.嵌套循环联结(NESTED LOOPS)2.哈希联结(HASH JOIN)3.排序合并联结(MERGE JOIN)4.半联结(in/exists)5.反联结(not in/not exists)6 ...

  4. grid+report 怎么在项目中使用

    grid+report 的例子很丰富,首先看你所用对应编程语言的例子.参考帮助的“产品介绍->快速入门指导”部分.根据快速入门指导中的说明,先把例子程序运行. 例子分两部分:1.报表模板例子,主 ...

  5. 微信小程序获取用户信息“授权失败”场景的处理

    很多的时候我们在处理小程序功能的时候需要用户获取用户信息,但是呢为了信息安全,用户不授权导致授权失败场景:但是小程序第二次不在启动授权信息弹层,为了用户体验,可以用以下方式处理: function i ...

  6. ceph在扩展mon节点时,要注意的问题

    我开始也是一步一步的按官方文档操作. 但后来还是遇到了问题. 当我要扩展mon节点时,死活出错. (我就一共用了三个节点ceph-admin, ceph-node1, ceph-node2) 比如: ...

  7. WebDriver自动化测试工具(1)---环境搭建

    Webdriver是一个前端自动化测试工具,可以模拟用户点击链接,填写表单,点击按钮等操作,下面介绍其使用 一.下载WebdriverC#类库以及对应浏览器驱动 http://www.selenium ...

  8. 使用vue2.0 vue-router vuex 模拟ios7操作

    其实你也可以,甚至做得更好... 首先看一下效果:用vue2.0实现SPA:模拟ios7操作 与 通讯录实现 github地址是:https://github.com/QRL909109/ios7 如 ...

  9. gulp在webstorm里运行,告别cmd控制台!

    使用webstorm运行gulp程序,不再用一直开着cmd了!鬼知道自己会不会不小心关闭了cmd呢.看截图操作吧! 如果你的gulp设置了default任务,那么直接点击“运行‘default‘’就行 ...

  10. Ljava/lang/Iterable与AbstractMethodError

    java.lang.AbstractMethodError: com.example.demo.repository.UserRepositoryImpl.findAll()Ljava/lang/It ...