MSSQL中循环
1 declare @result table
2 (
3 custid int,
4 ordermonth datetime,
5 qty int,
6 runqty int,
7 primary key(custid,ordermonth)
8 );
9
10 declare
11 @custid as int,
12 @prvcustid as int,
13 @ordermonth as datetime,
14 @qty as int,
15 @runqty as int;
16 declare c cursor fast_forward for --定义游标
17 select custid,ordermonth,qty
18 from Sales.CustOrders
19 order by custid,ordermonth;
20
21 open c --打开游标
22 fetch next from c into @custid,@ordermonth,@qty;
23 select @prvcustid = @custid,@runqty = 0;
24 while @@fetch_status = 0 --当不是最后一行记录时,函数返回0
25 begin
26 --Do something
27 end
28 close c; --关闭游标
29 deallocate c; --释放游标

2、通过特定ID。

1 declare @max int
2 declare @i int
3 select ROW_NUMBER() over (order by UnitId) as 'Id',RECID into #temp from UNIT
4 select @max=max(Id) from #temp
5 set @i = 1
6 while (@i <= @max)
7 begin
8 if @i = 10
9 begin
10 select * from UNIT where RECID = (select RECID from #temp where ID = @i) --11125166
11 break
12 end
13 set @i = @i + 1
14 end
15
16 drop table #temp

3.表
create table ta(id int,name datetime)
declare @i int ,@name datetime
set @i=0;
while @i<10
begin
set @i=@i+1
--insert into ta (id,name) values(@i,DATEADD(hh,@i,GETDATE()))
Select @name=name from ta where id=@i
print @name
end
select * from ta
MSSQL中循环的更多相关文章
- JavaScript中让Html页面中循环播放文字
JavaScript中让Html页面中循环播放文字 <html> <head> <meta http-equiv="Content-Type" con ...
- Mssql中一些常用数据类型的说明和区别
Mssql中一些常用数据类型的说明和区别 1.bigint 占用8个字节的存储空间,取值范围在-2^63 (-9,223,372,036,854,775,808) 到 2^63-1 (9,223,37 ...
- 说说你所熟知的MSSQL中的substring函数
说说你所熟知的MSSQL中的substring函数 *:first-child { margin-top: 0 !important; } body>*:last-child { margin- ...
- mysql数据表如何导入MSSQL中
本案例演示所用系统是windows server 2012.其它版本windows操作系统类似. 1,首先需要下载mysql odbc安装包. http://dev.mysql.com/downloa ...
- Java中循环删除list中元素的方法总结
印象中循环删除list中的元素使用for循环的方式是有问题的,但是可以使用增强的for循环,然后在今天使用的时候发现报错了,然后去科普了一下,发现这是一个误区.下面我们来一起看一下. Java中循环遍 ...
- [置顶] LOAD语句:利用MSSQL中的xp_cmdshell功能,将指定文件夹下的指定文件,生成mysql的LOAD语句
LOAD语句:利用MSSQL中的xp_cmdshell功能,将指定文件夹下的指定文件,生成mysql的LOAD语句 declare @sql varchar(4000), @dirpath varch ...
- 【JS中循环嵌套常见的六大经典例题+六大图形题,你知道哪几个?】
首先,了解一下循环嵌套的特点:外层循环转一次,内层循环转一圈. 在上一篇随笔中详细介绍了JS中的分支结构和循环结构,我们来简单的回顾一下For循环结构: 1.for循环有三个表达式,分别为: ①定义循 ...
- JAVA中循环删除list中元素的方法总结【转】
印象中循环删除list中的元素使用for循环的方式是有问题的,但是可以使用增强的for循环,然后今天在使用时发现报错了,然后去科普了一下,再然后发现这是一个误区.下面就来讲一讲..伸手党可直接跳至文末 ...
- js中return false; jquery中需要这样写:return false(); Jquery 中循环 each的用法 for循环
js中return false; jquery中需要这样写:return false(); Jquery 中循环 each的用法 $(".progressName").each(f ...
随机推荐
- [BZOJ 1724] Fence Repair
这大概是BZOJ里除了A+B Problem最水的一道题了吧 题面:http://www.lydsy.com/JudgeOnline/problem.php?id=1724 这道题其实有一些思路还是可 ...
- 【位运算】【BFS】移动玩具
1054: [HAOI2008]移动玩具 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2246 Solved: 1246[Submit][Stat ...
- BZOJ 1633 [Usaco2007 Feb]The Cow Lexicon 牛的词典(单调DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1633 [题目大意] 给出一个字符串和一个字符串集, 问要删去多少个字符该字符串才可以被 ...
- 【推导】Gym - 101243A - Fried Fish
题意:有n条鱼,煎一条鱼的一面要一分钟,锅只能同时煎K条鱼,问最少时间是? 想想小时候那个脑筋急转弯,3条鱼只需2分钟.可以大胆猜测,n条鱼,只需ceil(n*2/K)分钟,即一定能非常高效地煎完,每 ...
- python基础之模块,面向对象
hash 什么是hash? hash是一种算法,该算法接受传入的内容,经过运算得到一串hash值 为何用hash? hash值有三大特性: 1.只要传入的内容一样,得到的hash值必然一样 2.只要使 ...
- [NOIp2017提高组]宝藏
#include<cstdio> #include<cctype> #include<algorithm> inline int getint() { regist ...
- 记录SSD中的一些东西
AnnotatedDatum是存放图片和BBox的类 // 估计是一张图片就对应于一个AnnotatedDatummessage AnnotatedDatum { enum AnnotationTyp ...
- CentOS下OpenVPN实现公网IP映射到内网(iptables转发功能)(转)
说明:这种方案的实现前提是必须要有一台拥有公网IP的电脑,OpenVPN搭建过程很普通,关键技术在于iptables的转发.搭建教程可能有点旧了,可以只看iptables的关键点技术. 方案背景: 公 ...
- cocos2d-x Cygwin编译 recipe for target `obj/local/armeabi/libcocos2d.so' fail 解决办法
在编译cocos2d-x的helloworld 或者 tests的时候. 官网上使用ndk4.ndk5,这里是使用 ndkr7b.ndkr8或ndkr8b .操作会简单很多,但是出了些小问题也是很坑人 ...
- Android-25种开源炫酷动画框架
前言 忙碌的工作终于可以停息一段时间了,最近突然有一个想法,就是自己写一个app,所以找了一些合适开源控件,这样更加省时,再此分享给大家,希望能对大家有帮助,此博文介绍的都是UI上面的框架,接下来会有 ...