Reputation: 494
I know how to execute a stored procedure in SQL Server2008 but I'm clueless in executing a stored procedure containing a cursor in it.
My code:
BEGIN TRANSACTION
GO
DROP PROCEDURE SampleProcedure
GO
CREATE PROCEDURE SampleProcedure
AS
DECLARE @FirstName varchar(64)
DECLARE c1 CURSOR READ_ONLY
FOR
SELECT FIRST_NAME
FROM EMPLOYEE
OPEN c1
FETCH NEXT FROM c1 INTO @FirstName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @FirstName
FETCH NEXT FROM c1 INTO @FirstName
END
CLOSE c1
DEALLOCATE c1
COMMIT TRANSACTION
I have seen executing a procedure with cursor in Oracle but couldn't find in SQL Server. Please tell me how to execute the stored procedure which contains cursor.
---Thanks
Upvotes: 0
Views: 1914