I want to use the sql server sp_rename function, the problem is that I have to put it inside an exec, since the database on which it runs is dynamic and I have it inside a cursor. The fact is that the following sentence works correctly:
EXEC (@name+'..sp_rename "valores", "valores2"')
Since @name is the cursor variable indicated by the database on which it applies.
But if I try to do this
EXEC( 'select ''hola''; '
+@name+'..sp_rename "valores", "valores2"
')
I need to put a select before the execution of sp_rename but it does not work.
It has to be something of the syntax, but I'm going crazy and I do not get it.
If someone can give me a hand I would appreciate it.