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) = ''
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 脚本 多条记录遍历的更多相关文章
- SqlServer插入1000条记录
1.想在SqlServer中插入指定数量的测试记录怎么办? 2.解决: DECLARE @var INT ) BEGIN INSERT INTO test (Name) VALUES (convert ...
- 分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)
分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...
- (转)分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)
分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...
- 从SQLSERVER/MYSQL数据库中随机取一条或者N条记录
从SQLSERVER/MYSQL数据库中随机取一条或者N条记录 很多人都知道使用rand()函数但是怎麽使用可能不是每个人都知道 建立测试表 USE [sss] GO ,NAME ) DEFAULT ...
- SQLServer 分组查询相邻两条记录的时间差
原文:SQLServer 分组查询相邻两条记录的时间差 首先,我们通过数据库中表的两条记录来引出问题,如下图 以上为一个记录操作记录的表数据.OrderID为自增长列,后面依次为操作类型,操作时间,操 ...
- sqlserver -- 学习笔记(七)获取同组数据的前两条记录
不啰嗦,直接上图,大概实现效果如下: 有上面这样一份数据,将他们按照userAccount和submitTime进行分组,然后提前每组数据的前两条记录 提取后数据如下: 实现的SQL如下: selec ...
- SQLServer 触发器 同时插入多条记录有关问题
由于 SQL Server 的触发器, 没有 FOR EACH ROW (ORACL中有)的选项, 有时候不正确的使用 inserted 与deleted 可能会有点麻烦. 下面来一个简单的例子 -- ...
- sqlserver查询数据表中每个类别最新的一条记录
表tariff_info, 原始数据: 想要的结果:以start_time时间倒序排序, 以code分类, 查询每一类最新的一条记录 sql: SELECT a.* FROM TARIFF_INFO ...
- 分享一个SQLSERVER脚本
原文:分享一个SQLSERVER脚本 分享一个SQLSERVER脚本 很多时候我们都需要计算数据库中各个表的数据量很每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tablespac ...
随机推荐
- python 异步IO( asyncio) 协程
python asyncio 网络模型有很多中,为了实现高并发也有很多方案,多线程,多进程.无论多线程和多进程,IO的调度更多取决于系统,而协程的方式,调度来自用户,用户可以在函数中yield一个状态 ...
- 【swupdate文档 二】许可证
许可证 SWUpdate是免费软件.它的版权属于Stefano Babic和其他许多贡献代码的人(详情请参阅实际源代码和git提交信息). 您可以根据自由软件基金会发布的GNU通用公共许可证第2版的条 ...
- linux中断系统那些事之----中断处理过程【转】
转自:http://blog.csdn.net/xiaojsj111/article/details/14129661 以外部中断irq为例来说明,当外部硬件产生中断时,linux的处理过程.首先先说 ...
- 用pyperclip 模块拷贝粘贴字符串
>>> import pyperclip>>> pyperclip.copy('Hello world!')>>> pyperclip.paste ...
- C#数据没初始化,使用会报错,可以初始化null
protected void Page_Load(object sender, EventArgs e) { string[] A; if (B== 0) { A = new string[] {1, ...
- Python——turtle生成图片保存
代码示例如下: from Tkinter import * from turtle import * import turtle forward(100) ts = turtle.getscreen( ...
- REST,Web 服务,REST-ful 服务
介绍 REpresentational State Transfer (REST) 是一种架构原则,其中将 web 服务视为资源,可以由其 URL 唯一标识.RESTful Web 服务的关键特点是明 ...
- javascript方法--call()
关于call方法,以前经常看到这个方法,但是也没怎么用心去学习,后来觉得不行,所以知识在一点一点补~ 今天对自己学习call方法做一下总结 其实,学了call方法,会发现call跟apply其实是很像 ...
- jmeter压力测试案例实战
1. 测试目标地址:http://www.cnblogs.com/ 2. 1秒内有100个用户同时访问,看性能如何 3. 步骤 线程组.http请求.查看结果树.聚合报告 添加http请求如下: ...
- django-1366, "Incorrect string value: '\\xE6\\x88\\x9A\\xE4\\xBC\\x9F...'
今天把之前的一些代码转移到另外一台电脑的时候, python manage.py syncdb 的时候报了 (1366, "Incorrect string value: '\\xE6\\x ...