Possible Duplicate:
How can I make this query to accept dynamic table names?
I would like to create a new table from an exiting table using stored procedure. I am new in this but no problem learning. Anyway this is what I have done:
CREATE PROCEDURE usp_CreateNewTable
@NewTable nvarchar(1000),
@OldTable nvarchar(1000)
AS
SELECT *
INTO @NewTable
FROM @OldTable
WHERE 1 = 2
GO
It gives me an error:
Incorrect syntax near ‘@NewTable’
Please dig in and help…
You can use Dynamic SQL, something like this: