Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • 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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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