Solved

create a new table with a variable name

Posted on 2011-09-14
5
301 Views
Last Modified: 2012-05-12
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
Comment
Question by:ironpen45
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 36537387
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
 
LVL 4

Expert Comment

by:manishkungwani
ID: 36537389
The query is not correct, can you state what you want to do, so that I can suggest the right query for you.
0
 

Expert Comment

by:wenogk
ID: 36537410
Give me more into what you would like to do with this query and i'll just give you the code
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 250 total points
ID: 36537425

Declare @SQL VarChar(1000)

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

Exec ( @SQL)
0
 

Author Closing Comment

by:ironpen45
ID: 36537443
thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question