How can I use declared variables in the place of table names? What I am trying to do is write a stored proc that will take data from a linked server and put it into tables in a local DB. There are several tables that I have to deal with and was just wanting to assign the current local table name and the linked table name to variables and use them.
Here is a snippet
Right now it is showing me an error saying it is expecting a QuotedID.
Any advice?
Here is a snippet
Code:
@CURRENT_LOCAL_TABLE = 'ARIALOCAL.dbo.users'
@CURRENT_ARIA_TABLE = '[ARIA-MYSQL]...users'
SELECT @ROWCNT = (SELECT COUNT(*) FROM @CURRENT_ARIA_TABLE)
IF (@ROWCNT > 0)
BEGIN
BEGIN TRAN
-- Truncate the table if it exists locally
IF OBJECT_ID (@CURRENT_LOCAL_TABLE,'U') IS NOT NULL
BEGIN
TRUNCATE table @CURRENT_LOCAL_TABLE
END
Right now it is showing me an error saying it is expecting a QuotedID.
Any advice?