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
Microsoft SQL Server
Last Comment
hwassinger
8/22/2022 - Mon
Kent Dyer
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
hwassinger
ASKER
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.
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..
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?
That is probably the best way to think of this.
HTH,
Kent