Cursor

Arul44ece
Posted by Arul44ece under Sql Server category on | Points: 40 | Views : 1480
Hi ,

In the below query is example for cursor.

Here fetch record one by one from table .


declare @taskid varchar(50)

declare @task_details cursor //Declare cursor

set @task_details=cursor

FOR

select taskid from tasklist order by taskid desc

open @task_details //open the cursor

fetch next

from @task_details into @taskid

while @@FETCH_STATUS=0

begin

print @taskid

fetch next from @task_details into @taskid

end

close @task_details // close

deallocate @task_details // deallocation

Comments or Responses

Posted by: Jasminej on: 10/3/2012 Level:Starter | Status: [Member] | Points: 10
Is this working in SQL Server ?
Posted by: Arul44ece on: 11/28/2012 Level:Starter | Status: [Member] | Points: 10
Hi Jasmine,

Yes ,working fine.

did u face any issue

Login to post response