0
我不知道爲什麼這個查詢返回的第一行無限如何通過光標循環?
DECLARE db_cursor1 CURSOR FOR select ilduedt,accountno,ilno from TBPAYSCHED where accountno ='000520285344' and ilno!=0 order by id
DECLARE @ilduedt datetime;
DECLARE @accountno varchar(MAX);
DECLARE @ilno int;
DECLARE @tempdate datetime;
OPEN db_cursor1;
FETCH NEXT FROM db_cursor1 INTO @ilduedt,@accountno,@ilno
WHILE @@FETCH_STATUS = 0
BEGIN
select @ilduedt,@accountno,@ilno
END;
CLOSE db_cursor1;
DEALLOCATE db_cursor1;
tbpaysched
accountno | ilno | ilduedt
------------------------------------------
000520285344 0 2017-07-30 00:00:00.000
000520285344 1 2017-09-15 00:00:00.000
000520285344 2 2017-08-30 00:00:00.000
000520285344 3 2017-09-15 00:00:00.000
它只返回與ilno 1無限行。我不知道,但我想我錯過了一些愚蠢的東西。
你的問題的最佳答案是,你應該拋棄這個光標,並用基於集合的代碼重寫你的過程。 –