@@fetch_status值老不定?

dongkuang 2006-03-02 05:45:44
declare yb SCROLL CURSOR for
select id from equipment where equipment.id between @beginsid and @endsid order by equipment.sid
open yb
while @@fetch_status=0
begin
fetch next from yb into @@id
insert into equipmentysdtemp(equipmentsid,equipmentsidgo)
values(@beginsid,@@fetch_status)
continue
end
close yb
deallocate yb

用asp.net调用此存储过程,过几分钟第一次试就正常,以后连续试都擦入空白,经测试,是@@fetch_status值老不定,不知为什么?
...全文
126 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
msjqd 2006-03-04
同意 邹建老大
回复
zjcxc 2006-03-03
楼主的逻辑有问题
fetch 是取下一条数据, 取数据是否成功, 这个是未知的, 要通过@@fetch_status来判断.
而楼主在fetch后就直接插入了, 并没有理会fetch是否成功, 结果当然会有问题.
回复
mislrb 2006-03-03
同意楼上
回复
wgsasd311 2006-03-03
--楼主范了逻辑错误,应是先取值,再判断游标状态,试下面
--try
declare yb SCROLL CURSOR for
select id from equipment where equipment.id between @beginsid and @endsid order by equipment.sid
open yb
fetch next from yb into @@id
while @@fetch_status=0
begin
insert into equipmentysdtemp(equipmentsid,equipmentsidgo)
values(@beginsid,@@fetch_status)
fetch next from yb into @@id
end
close yb
deallocate yb
回复
-渔民- 2006-03-03
學習
回复
dongkuang 2006-03-02
这个我知道,就是想知道为啥@@fetch_status值老不定?因为我以前的系统这样用的,没问题,为啥现在有,是不是都要改
回复
zlp321002 2006-03-02
--try
declare yb SCROLL CURSOR for
select id from equipment where equipment.id between @beginsid and @endsid order by equipment.sid
open yb
Fetch yb Into @@id
while @@fetch_status=0
begin
insert into equipmentysdtemp(equipmentsid,equipmentsidgo)
values(@beginsid,@@fetch_status)
Fetch yb Into @@id
end
close yb
deallocate yb
回复
zlp321002 2006-03-02
--try
declare yb SCROLL CURSOR for
select id from equipment where equipment.id between @beginsid and @endsid order by equipment.sid
open yb
while @@fetch_status=0
begin
insert into equipmentysdtemp(equipmentsid,equipmentsidgo)
values(@beginsid,@@fetch_status)
fetch next from yb into @@id
end
close yb
deallocate yb
回复
相关推荐
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2006-03-02 05:45
社区公告
暂无公告