请大家帮我看看这个存储过程中的游标有什么问题,为什么不循环
CREATE proc lstable1
@IDcode varchar(100)
as
truncate table ls
declare cur_ls cursor
for select 收款单位,品名,等级,SDate,EDate from 付款凭证 where order_id=@IDcode
open cur_ls
declare
@CusName Varchar(100),
@StartTime datetime,
@EndTime datetime,
@Mname varchar(100),
@GradeName varchar(100)
if @@error =0
begin
while @@fetch_status=0
begin
fetch next from cur_ls into @CusName,@Mname,@GradeName,@StartTime,@EndTime
if @@fetch_status=0
begin
insert ls(品名,等级,数量,ID)
select Mname,GradeName,Jweight,IDcode from
app_v_ponderation where
(jweight is not null) and
(CusName like @CusName) and
(Mname like @Mname) and
(GradeName like @GradeName) and
(billdate between @starttime and @endtime) and
(remark like '%入% ')
order by id
end
else
break
end
end
close cur_ls
deallocate cue_ls
GO
------解决方案----------------------参考,你的貌似少了一个fetch
DECLARE t_Cursor CURSOR FOR
select * ……
OPEN t_Cursor
FETCH NEXT FROM t_Cursor into @a……
WHILE @@FETCH_STATUS = 0
BEGIN
……
FETCH NEXT FROM t_Cursor into @a……
END
CLOSE t_Cursor
DEALLOCATE t_Cursor
------解决方案----------------------try
CREATE proc lstable1
@IDcode varchar(100)
as
truncate table ls
declare cur_ls cursor
for select 收款单位,品名,等级,SDate,EDate from 付款凭证 where order_id=@IDcode
open cur_ls
declare
@CusName Varchar(100),