Solved

create a new table with a variable name

Posted on 2011-09-14
5
271 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility

Declare @SQL VarChar(1000)

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

Exec ( @SQL)
0
 

Author Closing Comment

by:ironpen45
Comment Utility
thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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 …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

771 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

14 Experts available now in Live!

Get 1:1 Help Now