SQL 游标

declare @MId bigint
declare update_network cursor for   --定义游标
select MerchantId from Sys_CCOO_Network
open update_network   --打开游标
fetch next from update_network into @MId
WHILE @@FETCH_STATUS = 0  --执行循环
BEGIN
declare @packageId bigint=0
select top 1 @packageId=B.PackageId from sys_ccoo_order A join
Sys_CCOO_PurchaseRecords B on A.Id =B.corderId
join Sys_Product C
on C.Id=B.PackageId
and C.packageService='YWFW'
where A.MerchantId=@MId
if(ISNULL(@packageId,0)>0)
begin
update Sys_CCOO_Network set defaultpackageId=@packageId where MerchantId=@MId
end
fetch next from update_network into @MId
END
CLOSE update_network  --关闭游标
DEALLOCATE update_network  --释放游标

posted @ 2015-06-08 15:40  sulin  阅读(146)  评论(0)    收藏  举报