user2456195
user2456195

Reputation: 67

Anyone know what is wrong here?

BEGIN
OPEN DQC_Cursor1 ; 
LOOP

FETCH DQC_Cursor1 INTO @table_name1 ; 
EXIT when DQC_Cursor1%notfound;
EXEC Incorporate @table_name = @table_name1,
    @historical_table_name = Replace(
        @table_name1,
        'Temp',
        'Historical'
    ) ;

END EXEC;
END LOOP;


CLOSE DQC_Cursor1;
commit;
END;

The error messages that i get is as follows. I also getting incorrect syntax near ;, expecting conversation when i hover over the underlined error. I have the stored procedure incorporated already written out. Anyone know what is going wrong here?

Incorrect syntax near 'LOOP'.
Incorrect syntax near the keyword 'EXIT'.

Upvotes: 0

Views: 1549

Answers (1)

AR.
AR.

Reputation: 40327

I assume Incorporate is a stored procedure you have. As the comments suggest, you're a bit mixed up on your cursor syntax and reading through the documentation will help a lot. But in this specific case, try:

declare @table_name1 varchar(max);

declare DQC_Cursor1 cursor
for
    select Table_Name
    from TableNames;

open DQC_Cursor1
fetch next from DQC_Cursor1 into @table_name1
while @@FETCH_STATUS = 0 
    begin
        exec Incorporate @table_name = @table_name1,
                @historical_table_name = replace(@table_name1,'Temp','Historical')
    end
close DQC_Cursor1;
deallocate DQC_Cursor1;

Upvotes: 1

Related Questions