0

I am try to make a cursor with loop condition. purpose of cursor:- I want to execute a procedure 17times .

Procedure definition:

dbo.ALLAARTI_MIS_SUMMARY @IN_SYSDIFF = @IN_DIFF
DECLARE @IN_DIFF int
DECLARE vendor_cursor CURSOR FOR
SELECT date_time FROM dumy_mis 
OPEN vendor_cursor
FETCH NEXT FROM vendor_cursor 
INTO @IN_DIFF
WHILE @@FETCH_STATUS = 0
BEGIN
exec dbo.ALLAARTI_MIS_SUMMARY @IN_SYSDIFF = @IN_DIFF
END
CLOSE vendor_cursor 
DEALLOCATE vendor_cursor
asked Nov 28, 2017 at 9:30
0

1 Answer 1

1

I'm not sure what are you trying to achieve with this script, but you should fetch next records inside WHILE block just to be sure that @@FETCH_STATUS=0

dbo.ALLAARTI_MIS_SUMMARY @IN_SYSDIFF = @IN_DIFF
DECLARE @IN_DIFF int
DECLARE vendor_cursor CURSOR FOR
SELECT date_time FROM dumy_mis 
OPEN vendor_cursor
FETCH NEXT FROM vendor_cursor 
INTO @IN_DIFF
WHILE @@FETCH_STATUS = 0
BEGIN
 exec dbo.ALLAARTI_MIS_SUMMARY @IN_SYSDIFF = @IN_DIFF
 FETCH NEXT FROM vendor_cursor 
 INTO @IN_DIFF
END
CLOSE vendor_cursor 
DEALLOCATE vendor_cursor
answered Nov 28, 2017 at 9:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.