tamathaltarak
Programmer
Hi,
Can someone please help me and show me where I am going wrong with this.
I am creating a stored procedure that uses a cursor to execute an insert statement. What I can't seem to do is pass parameters to the cursor.
I end up with invalid object @sTable. Any ideas ???
Any help will be really appreciated.
Thanks in advance :-;
Tamath Altarak
Can someone please help me and show me where I am going wrong with this.
I am creating a stored procedure that uses a cursor to execute an insert statement. What I can't seem to do is pass parameters to the cursor.
I end up with invalid object @sTable. Any ideas ???
Code:
CREATE PROCEDURE SP_MYPROCEDURE (@sTable SYSNAME) AS
DECLARE @x INT
DECLARE @y INT
DECLARE @z INT
DECLARE my_cursor CURSOR FOR
SELECT x, y, z FROM @sTable
OPEN my_cursor
FETCH NEXT FROM my_cursor INTO @x, @y, @z
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
INSERT INTO MyTable (x, y, z)
VALUES (@x, @y, @z)
FETCH NEXT FROM my_cursor INTO @x, @y, @z
END
CLOSE my_cursor
DEALLOCATE my_cursor
GO
Any help will be really appreciated.
Thanks in advance :-;
Tamath Altarak