Solved

SQL syntax with a restricted word

Posted on 2013-01-01
6
270 Views
Last Modified: 2013-01-02
I needto execute a query to copy a complete table from one database (not on this SQL server) into a new database using a linked server. The complication seems to be that the table is named "FUNCTION"


--Select * into "FUNCTION from openquery(NEW,' select * from FUNCTION') this statement fails

I cannot rename the source table
0
Comment
Question by:hwassinger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 38735203
SELECT INTO is reserved as you are trying to SELECT * INTO NEW_TABLE FROM OLD_TABLE

That is probably the best way to think of this.

HTH,

Kent
0
 

Author Comment

by:hwassinger
ID: 38735206
Kent

thats not going to be it as I have MANY other queries that seem to be working with this syntax.... It seems tio be related to the FUNCTION as the table name.
0
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 total points
ID: 38735208
You can usually get around reserved words be enclosing them in square brackets like so: [function]

Not sure if that will work inside openquery though.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 65

Expert Comment

by:Jim Horn
ID: 38735327
Guessing the above square bracket solution would work.

I understand you can't rename the source table, but a possible workaround if the above doesn't work would be to create a view that does a SELECT * FROM FUNCTION, and save it as a name that isn't a reserved word.

>I have MANY other queries that seem to be working with this syntax
Hmm... if this is correct, and square brackets don't work, you might be somewhat hosed..
0
 
LVL 8

Expert Comment

by:jpgobert
ID: 38735406
So... I'm curious why you wouldn't fully qualify the table names since you're working with two tables in the same query with the same name, let alone the fact that it is a reserved word... brackets will fix SQL thinking your table name is an actual reserved command word...

I know you have a linked server connection in place but I'd definitely write it out as

[SERVER].[DATABASE].DBO.[FUNCTION]

What's the actual error that SQL throws at you on this?
0
 

Author Closing Comment

by:hwassinger
ID: 38736291
thanks
0

Featured Post

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
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 ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

751 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