|
I am trying to create a cursor that is uses dynamic SQL however the below procedure is erroring with "variable assignment is not allowed in a cursor declaration."
create procedure loadcode @tabname varchar(50)
as
DECLARE @tabload varchar(8000)
DECLARE @client VARCHAR(10)
DECLARE cur1 CURSOR FAST_FORWARD FOR
SELECT @tabload = 'SELECT client FROM ' + @tabname + '__TEXT'
OPEN cur1
FETCH NEXT FROM cur1
INTO @client
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT + @client
FETCH NEXT FROM cur1
INTO @client
END
CLOSE cur1
DEALLOCATE cur1
EXEC (@tabload)
I need to run an IF THEN ELSE insert into another table from the cursors output so how can I create this cursor? And if I was to use a WHILE loop how could it be coded? TIA
(comments are locked)
|
|
Got it to work. For the record you need to declare the whole cursor from within dynamic sql. Please note that you can accept your own answer (which will marked the question as "Answered")
Dec 03 '09 at 09:33 AM
Kristen ♦
(comments are locked)
|


Can you give more informations on why you need to do this via cursor?