Solved

SQL syntax with a restricted word

Posted on 2013-01-01
6
262 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
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert formula to max at a specific date by month 18 19
MS SQL with ODBC 5 36
Live Storage Vmotion VMs with shared VMDK 10 58
T-SQL:  Collapsing 9 25
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

778 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