• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

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!
0
ironpen45
Asked:
ironpen45
1 Solution
 
É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
 
Éric MoreauSenior .Net ConsultantCommented:

Declare @SQL VarChar(1000)

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

Exec ( @SQL)
0
 
ironpen45Author Commented:
thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now