Solved

create a new table with a variable name

Posted on 2011-09-14
5
284 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 69

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 69

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now