![]() | |
![]() |
| | Thread Tools | Display Modes |
#41
| |||
| |||
|
|
This, also, will not work. You cannot use a variable in the FROM clause of a query under any conditions. The above concept is valid; however, the execution is incorrect. Given a preexisting variable @table_name containing a valid two-part table name. DECLARE @query varchar(max) SET @query = 'SELECT * FROM ' + @table_name EXEC (@query) You could also skip the @query variable and simply: EXEC('SELECT * FROM ' + @table_name) |
|
what about a cursor? |
#42
| |||
| |||
|
|
This, also, will not work. You cannot use a variable in the FROM clause of a query under any conditions. The above concept is valid; however, the execution is incorrect. Given a preexisting variable @table_name containing a valid two-part table name. DECLARE @query varchar(max) SET @query = 'SELECT * FROM ' + @table_name EXEC (@query) You could also skip the @query variable and simply: EXEC('SELECT * FROM ' + @table_name) |
|
what about a cursor? |
![]() |
| Thread Tools | |
| Display Modes | |
| |