SQL CURSOR
SET NOCOUNT ON; DECLARE @vendor_id int, @vendor_name nvarchar(50),
@message varchar(80), @product nvarchar(50); PRINT '-------- Vendor Products Report --------'; DECLARE vendor_cursor CURSOR FOR
SELECT VendorID, Name
FROM Purchasing.Vendor
WHERE PreferredVendorStatus = 1
ORDER BY VendorID; OPEN vendor_cursor FETCH NEXT FROM vendor_cursor
INTO @vendor_id, @vendor_name WHILE @@FETCH_STATUS = 0
BEGIN
PRINT ' '
SELECT @message = '----- Products From Vendor: ' +
@vendor_name PRINT @message -- Declare an inner cursor based
-- on vendor_id from the outer cursor. DECLARE product_cursor CURSOR FOR
SELECT v.Name
FROM Purchasing.ProductVendor pv, Production.Product v
WHERE pv.ProductID = v.ProductID AND
pv.VendorID = @vendor_id -- Variable value from the outer cursor OPEN product_cursor
FETCH NEXT FROM product_cursor INTO @product IF @@FETCH_STATUS <> 0
PRINT ' <<None>>' WHILE @@FETCH_STATUS = 0
BEGIN SELECT @message = ' ' + @product
PRINT @message
FETCH NEXT FROM product_cursor INTO @product
END CLOSE product_cursor
DEALLOCATE product_cursor
-- Get the next vendor.
FETCH NEXT FROM vendor_cursor
INTO @vendor_id, @vendor_name
END
CLOSE vendor_cursor;
DEALLOCATE vendor_cursor;
SQL CURSOR的更多相关文章
- SQL Cursor生命周期
阅读导航 1 Cursor Step 1.1 Create cursor 1.2 Parse statement 1.3 descript and define 1.4 Bind variable ...
- Sql Cursor example
USE [EUC]GO/****** Object: StoredProcedure [dbo].[SP_SME_QueryAuditLog] Script Date: 02/05/2015 ...
- SQL Cursor 基本用法
1 table1结构如下 2 id int 3 name varchar(50) 4 5 declare @id int 6 declare @name varchar(50) ...
- sql Cursor的用法
table1结构如下 id int name ) declare @id int ) declare cursor1 cursor for --定义游标cursor1 select * from ta ...
- 游标SQL Cursor 基本用法
http://www.cnblogs.com/Gavinzhao/archive/2010/07/14/1777644.html 1 table1结构如下 2 id int 3 name va ...
- SQL Cursor 基本用法[用两次FETCH NEXT FROM INTO语句?]
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> ...
- SQL Cursor 游标的使用
DECLARE @name VARCHAR(50) --声明游标 DECLARE cursor_VAA1 CURSOR FOR SELECT VAA05 FROM VAA1 --打开游标 OPEN ...
- SQL Cursor(游标)
1.游标在数据表没有id(identity(1,1))时好用,但是游标会吃更多的内存,减少可用的并发,占用宽带,锁定资源,当然还有更多的代码量 2.如果能不用游标,尽量不要使用游标,用完用完之后一定要 ...
- android sql Cursor
Cursor 是每行的集合. 使用 moveToFirst() 定位第一行. 你必须知道每一列的名称.你必须知道每一列的数据类型.Cursor 是一个随机的数据源. 所有的数据都是通过下标取得. Cu ...
随机推荐
- SQL Server 2008 R2 企业版/开发版/标准版(中英文下载,带序列号)
一. 简体中文 1. SQL Server 2008 R2 Developer (x86, x64, ia64) – DVD (Chinese-Simplified) File Name: cn_sq ...
- 25条提高iOS App性能的建议和技巧
这篇文章来自iOS Tutorial Team 成员 Marcelo Fabri, 他是 Movile 的一个iOS开发者. Check out his personal website or fol ...
- 利用office2010 word2010生成目录
详细内容可以从以下链接下载: http://www.360disk.com/file-37040.html 从前一直用word的目录功能,觉得很方便.第一:可以在目录的首页通过Ctrl+鼠标单击左键可 ...
- 8-05分支结构CASE..END
语法: CASE WHEN 条件1 THEN 结果1 WHEN 条件2 THEN 结果2 ...ELSE 其他结果 END 执行顺序: 条件1成立执行结果1 条件2成立执行结果2 如果所有WH ...
- 【MongoDB】5.MongoDB与java的简单结合
1.首先 你的清楚你的MongoDB的版本是多少 就下载对应的架包 下载地址如下: http://mongodb.github.io/mongo-java-driver/ 2.新建一个项目 把架包 ...
- 作弊Q-百威
===_=374793763===_= 2652880032 865580818 大康 2652880032 春牛 3479301404 皮卡丘 3242026908 舍得放手
- C# 默认以管理员权限运行程序
/** * 当前用户是管理员的时候,直接启动应用程序 * 如果不是管理员,则使用启动对象启动程序,以确保使用管理员身份运行 */ //获得当前登录的Windows用户标示 //URL:http://w ...
- iOS 设置1像素的UIView线
如果是代码实现,直接 在CGRectMake里把对应的参数设置为: 1.0/[UIScreenmainScreen].scale 即可. 如果是用xib实现,就需要将对应的限制拖一个I ...
- 字典树 - A Poet Computer
The ACM team is working on an AI project called (Eih Eye Three) that allows computers to write poems ...
- c语言指针疑惑[转载]
c99的动态数组是在栈上面开辟的,而new出来的是在堆上面开辟的.栈和堆的地址是从两端相向增长的.栈很小,一般只有几十k,vc6好像是64k.堆很大,在win32的虚拟地址空间可以分配到2g的内存.栈 ...