Sql Server 游标使用 demo
1 -- 创建游标
2 declare curUser cursor for
3 select top 30 email from dbUser
4 where hasdone=0
5
6 open curUser
7
8 declare @emailaddr varchar(200)
9 fetch next from curUser into @emailaddr
10
11 while( @@Fetch_Status=0 )
12 begin
13 print @emailaddr
14 fetch next from curUser into @emailaddr
15 end
16
17 -- 关闭游标
18 close curUser
19 deallocate curUser
20
2 declare curUser cursor for
3 select top 30 email from dbUser
4 where hasdone=0
5
6 open curUser
7
8 declare @emailaddr varchar(200)
9 fetch next from curUser into @emailaddr
10
11 while( @@Fetch_Status=0 )
12 begin
13 print @emailaddr
14 fetch next from curUser into @emailaddr
15 end
16
17 -- 关闭游标
18 close curUser
19 deallocate curUser
20