Declan Basile
asked on
Referencing a table with a table variable
In SQL Server 2012, Is there a way to create a table variable that references a table already in the database? Note: I have a string variable that contains the name of the table.
DECLARE @tablename As varchar(MAX)
DECLARE @TB As Table
SET @tableName = 'table1'
SET @TB = table with name 'table1'
SELECT * FROM @TB
Note: I'm asking if I could do this without dynamic sql, I already know that I could do 'EXEC sp_executesql 'SELECT * FROM ' + @tableName.
DECLARE @tablename As varchar(MAX)
DECLARE @TB As Table
SET @tableName = 'table1'
SET @TB = table with name 'table1'
SELECT * FROM @TB
Note: I'm asking if I could do this without dynamic sql, I already know that I could do 'EXEC sp_executesql 'SELECT * FROM ' + @tableName.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER