I dont know why this query returns only the first row infinitely
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 It only returns the row with ilno 1 infinitely. I dont know but I think I'm missing something stupid.