• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

SQL syntax with a restricted word

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
hwassinger
Asked:
hwassinger
1 Solution
 
Kent DyerIT Security Analyst SeniorCommented:
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
 
hwassingerAuthor Commented:
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
 
Steve WalesSenior Database AdministratorCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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
 
jpgobertCommented:
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
 
hwassingerAuthor Commented:
thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now