create a new table with a variable name

i keep getting "Msg 102, Level 15, State 1, Line 26 Incorrect syntax near '@newtbl'."

for

SELECT * INTO @newtbl FROM TMP8.dbo.tblQuery8

please help. thanks!
ironpen45Asked:
Who is Participating?
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:

Declare @SQL VarChar(1000)

SELECT @SQL = 'SELECT * INTO ' + @newtbl + ' FROM TMP8.dbo.tblQuery8'

Exec ( @SQL)
0
 
Éric MoreauSenior .Net ConsultantCommented:
you have to use dynamic SQL.

check "Dynamic SQL in a stored procedure" from http://www.sqlteam.com/article/introduction-to-dynamic-sql-part-1
0
 
manishkungwaniCommented:
The query is not correct, can you state what you want to do, so that I can suggest the right query for you.
0
 
wenogkCommented:
Give me more into what you would like to do with this query and i'll just give you the code
0
 
ironpen45Author Commented:
thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.