I am trying to create a stored procedure that selects from a database name that would be parameterized. However, I am having a lot of trouble doing so. I am trying to perform something as simple as the following:
DECLARE @tableName VARCHAR
SET @tableName = 'MY_TABLE_NAME'
SELECT
*
FROM
@tableName
This produces the error: Incorrect syntax near '@tableName'.
Could someone please tell me how I could select from a parameterized table name?
Execute dynamic SQL in this case.