LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

SQL Server使用游標及循環方法遍歷表中的數據

admin
2011年3月3日 20:38 本文熱度 3361
方法一:使用游標


SQL code
 
declare @ProductName nvarchar(50)  
declare pcurr cursor for select ProductName from Products
open pcurr
fetch next from pcurr into @ProductName
while (@@fetch_status = 0)
begin
print (@ProductName)
fetch next from pcurr into @ProductName
end
close pcurr
deallocate pcurr
declare @ProductName nvarchar(50)
declare pcurr cursor for select ProductName from Products
open pcurr
fetch next from pcurr into @ProductName
while (@@fetch_status = 0)
begin
print (@ProductName)
fetch next from pcurr into @ProductName
end
close pcurr
deallocate pcurr

此方法適用所有情況,對標結構沒有特殊要求。


方法二:使用循環



SQL code
 
declare @ProductName nvarchar(50)  
declare @ProductID int
select @ProductID=min(ProductID) from Products
while @ProductID is not null
begin
select @ProductName=ProductName from Products where

ProductID=@ProductID
print(@ProductName);
select @ProductID=min(ProductID) from Products where

ProductID>@ProductID
end
declare @ProductName nvarchar(50)
declare @ProductID int
select @ProductID=min(ProductID) from Products
while @ProductID is not null
begin
select @ProductName=ProductName from Products where
ProductID=@ProductID
print(@ProductName);
select @ProductID=min(ProductID) from Products where
ProductID>@ProductID
end

此方法適用于表帶有自動增加標識的字段


該文章在 2011/3/3 20:38:11 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved

黄频国产免费高清视频,久久不卡精品中文字幕一区,激情五月天AV电影在线观看,欧美国产韩国日本一区二区
亚洲国产日韩欧美在线看片 | 亚洲国产午夜精品理论片13 | 综合福利久久一级免费 | 亚洲熟女少妇精品 | 亚洲电影手机在线五月 | 亚洲第一精品小视频在线观看 |