declare myCursor cursor for select column1 from textTable open myCursor declare @a1 int fetch next from myCursor into @a1 print @a1 while @@fetch_status =0 begin print @a1 fetch next from myCursor into @a1 end close myCursor deallocate myCursor
--try declare myCursor cursor for select column1 from textTable open myCursor declare @a1 int fetch next from myCursor into @a1 print @a1 while @@fetch_status =0 begin print @a1 fetch next from myCursor into @a1 end close myCursor deallocate myCursor
open myCursor declare @a1 int fetch next from myCursor into @a1 while @@fetch_status =0 begin print @a1 fetch next from myCursor into @a1 end 这样看看
如果这样: print @a1 fetch next from myCursor into @a1 答案就是: 2 2 4 6 8 ------------------------------------------- 这回8是读了一次,但2读了两次,
declare myCursor cursor for select column1 from textTable open myCursor declare @a1 int 你思路不对,应是先判断是否取得数据,如取得数据则打印出来。所以稍改动如下: fetch next from myCursor into @a1
while @@fetch_status =0 begin print @a1 fetch next from myCursor into @a1
end close myCursor deallocate myCursor
--你思路不对,应是先判断是否取得数据,如取得数据则打印出来。所以稍改动如下: declare myCursor cursor for select column1 from textTable open myCursor declare @a1 int fetch next from myCursor into @a1
while @@fetch_status =0 begin print @a1 fetch next from myCursor into @a1
for select column1 from textTable
open myCursor
declare @a1 int
fetch next from myCursor into @a1
print @a1
while @@fetch_status =0
begin
print @a1
fetch next from myCursor into @a1
end
close myCursor
deallocate myCursor
declare myCursor cursor
for select column1 from textTable
open myCursor
declare @a1 int
fetch next from myCursor into @a1
print @a1
while @@fetch_status =0
begin
print @a1
fetch next from myCursor into @a1
end
close myCursor
deallocate myCursor
declare @a1 int
fetch next from myCursor into @a1
while @@fetch_status =0
begin
print @a1
fetch next from myCursor into @a1
end
这样看看
print @a1
fetch next from myCursor into @a1
答案就是:
2
2
4
6
8
-------------------------------------------
这回8是读了一次,但2读了两次,
for select column1 from textTable
open myCursor
declare @a1 int
你思路不对,应是先判断是否取得数据,如取得数据则打印出来。所以稍改动如下: fetch next from myCursor into @a1
while @@fetch_status =0
begin
print @a1
fetch next from myCursor into @a1
end
close myCursor
deallocate myCursor
declare myCursor cursor
for select column1 from textTable
open myCursor
declare @a1 int
fetch next from myCursor into @a1
while @@fetch_status =0
begin
print @a1
fetch next from myCursor into @a1
end
close myCursor
deallocate myCursor