I was trying to create new tables using the identifier through a list.
DECLARE @Counter INT, @TableName NVARCHAR(20)
SET @Counter = 1
WHILE (@Counter <= 20)
BEGIN
SELECT @TableName = TableName FROM [dbo].[TableList] WHERE index = @Counter
SELECT * INTO [dbo].[@TableName.combine] FROM [dbo].[@TableName] t
LEFT JOIN [dbo].[cost] c ON t.x = c.y
SET @Counter = @Counter +1
END
And it keeps saying the object of [dbo].[@TableName] is invalid, but I already have [dbo].[@TableName] as a table. I looked over the declare table variable, but [dbo].[@TableName] already existed in the database, how can I point to the table that I want?