Use of Cursor in Stored Procedure


Wednesday, October 7, 2009

Using below code you can learn, how to use cursor in Stored Procedure

DECLARE @dListingEnddate datetime

DECLARE cur_enddate1 CURSOR FOR( select top 10 dListingEnddate as dListingEnddate from jau_productmaster)

/* Open Corsor */
OPEN cur_enddate1

FETCH NEXT From cur_enddate1 INTO @dListingEnddate

WHILE @@Fetch_Status = 0

BEGIN
/*Put your sql query here*/
--INSERT INTO GK_ShareEvent (iShareEventID,iEventAudienceID)
--VALUES(@iEventID,@iEventAudienceID)

FETCH NEXT From cur_enddate1 INTO @dListingEnddate

END

/* Close Corsor */
CLOSE cur_enddate1

DEALLOCATE cur_enddate1

END




-------------------------------------------------------------------------------------------
Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com

No comments :