I am trying to display the records form particular table using cursor. But its throwing this error.
Msg 16916, Level 16, State 1, Procedure testload, Line 26 [Batch Start Line 1]
A cursor with the name 'ShowSDFinfo' does not exist.Msg 16916, Level 16, State 1, Procedure testload, Line 40 [Batch Start Line 1]
A cursor with the name 'ShowSDFinfo' does not exist.Msg 16916, Level 16, State 1, Procedure testload, Line 62 [Batch Start Line 1]
A cursor with the name 'ShowSDFinfo' does not exist.Msg 16916, Level 16, State 1, Procedure testload, Line 63 [Batch Start Line 1]
A cursor with the name 'ShowSDFinfo' does not exist.
Code:
CREATE OR ALTER PROCEDURE testload
AS
BEGIN
SET NOCOUNT ON;
DECLARE @VantiveOrgID1 VARCHAR(12),
@VantiveCustomerName1 VARCHAR(12),
@Sector1 VARCHAR(12)
--DECLARE AND SET COUNTER.
DECLARE @Counter INT
SET @Counter = 1
--DECLARE THE CURSOR FOR A QUERY.
DECLARE ShowSFDinfo CURSOR STATIC LOCAL READ_ONLY FOR
SELECT
[Vantive OrgID],
[Vantive Customer Name],
[Sector]
FROM
[dbo].[SCASalesOrderExport_20180416] WITH (nolock)
WHERE
date >= '1/1/18'
ORDER BY
date DESC;
--OPEN CURSOR.
OPEN ShowSDFinfo;
--FETCH THE RECORD INTO THE VARIABLES.
FETCH NEXT FROM ShowSDFinfo INTO @VantiveOrgID1, @VantiveCustomerName1, @Sector1
--LOOP UNTIL RECORDS ARE AVAILABLE.
WHILE @@FETCH_STATUS = 0
BEGIN
IF @Counter = 1
BEGIN
SELECT @@CURSOR_ROWS
END
FETCH NEXT FROM ShowSDFinfo INTO
@VantiveOrgID1
,@VantiveCustomerName1
,@Sector1
END
CLOSE ShowSDFinfo
DEALLOCATE ShowSDFinfo
END