I am not sure how to get the syntax of this right.
So I have a cursor that loops through a table User.Persona and captures the Id column. So each Id is stored into the variable cur_id with every iteration of the cursor. And each Persona Id will correspond to a Persona Id Table. For example Persona ID 1 has a Persona1 table, Persona Id 2 has a Persona2 table.
So in that cursor, I want to call the table SELECT....FROM @Persona# WHERE...
How do I do this?
I've tried storing the string of the table name in a variable first:
DECLARE cur_table VARCHAR(25);
And inside the cursor:
SELECT CONCAT('persona', @cur_id) INTO @cur_table
SELECT .... FROM **@cur_table** WHERE...
However, the FROM @cur_table throws an error and I cannot reference my string that holds the current table name.
Is there a way for me to reference the changing table names within my cursor?
Thanks!