sql - Table name as variable -


I am trying to execute this query:

  declared @tablename varchar (50) Select @tablename = 'test' from @tablename  

This generates the following error:

Message 1087, Level 16, State 1, Line 5 <

It is necessary to declare the table valley "@tablename".

If the query is still stable, the table name and column name must be fixed. For dynamic tables or column names, you should dynamically generate full SQL, and use sp_executesql to execute it.

More details here:


Comments