SQL Server‎ > ‎

Standard syntax to use a cursor in a stored procedure

--variables needed
declare @symbol nvarchar(50);

declare mycursor CURSOR for
Select distinct symbol from table
Open mycursor
Fetch next from mycursor
into @symbol
While @@FETCH_STATUS =0
BEGIN

    (write some code here....)


Fetch next from mycursor
into @symbol
END
Close mycursor;
Deallocate mycursor;


Comments