Hi,
I was trying to perform a one of task to gather information from LOADS of tables from two different SQL Server 2000 DBs. They are both similar, but one is the backend of a LIVE system, the other is the backend of a TEST system. As such, there are likely to be several structural differences between them.
Also, they reside on different servers.
I have collated a load of table & field details in a spreadsheet, and produced a load of SQL commands to copy into Query Analyzer. I then run the code from a local database.
This is in the following format for each table/field combo:
IF EXISTS (SELECT * FROM [remoteserver].[dbname].dbo.[sysobjects] WHERE [name] = (N'tablename'))
INSERT INTO SomeLocalTable (SomeField) SELECT [AnyField] AS [SomeField] FROM [remoteserver].[dbname].dbo.[tablename]
Therefore testing that the table exists before trying to extract data from it.
However, when it comes across a table that does not exist the following error is returned:
Server: Msg 7314, Level 16, State 1, Line 1
OLE DB provider 'remoteserver' does not contain table '"dbname"."dbo"."tablename"'. The table either does not exist or the current user does not have permissions on that table.
The IF EXIST is supposed to stop this happening.
Now, I know that this would work if it was all run on the same server as the source table(s).
Why does it ignore the check and try to parse the INSERT INTO line when the source table is on a remote server?
Is there anyway to prevent this behaviour?
I know that some tables will not exist on one version of the DB, and I want to skip past those lines.
Many thanks,
Simon
I was trying to perform a one of task to gather information from LOADS of tables from two different SQL Server 2000 DBs. They are both similar, but one is the backend of a LIVE system, the other is the backend of a TEST system. As such, there are likely to be several structural differences between them.
Also, they reside on different servers.
I have collated a load of table & field details in a spreadsheet, and produced a load of SQL commands to copy into Query Analyzer. I then run the code from a local database.
This is in the following format for each table/field combo:
IF EXISTS (SELECT * FROM [remoteserver].[dbname].dbo.[sysobjects] WHERE [name] = (N'tablename'))
INSERT INTO SomeLocalTable (SomeField) SELECT [AnyField] AS [SomeField] FROM [remoteserver].[dbname].dbo.[tablename]
Therefore testing that the table exists before trying to extract data from it.
However, when it comes across a table that does not exist the following error is returned:
Server: Msg 7314, Level 16, State 1, Line 1
OLE DB provider 'remoteserver' does not contain table '"dbname"."dbo"."tablename"'. The table either does not exist or the current user does not have permissions on that table.
The IF EXIST is supposed to stop this happening.
Now, I know that this would work if it was all run on the same server as the source table(s).
Why does it ignore the check and try to parse the INSERT INTO line when the source table is on a remote server?
Is there anyway to prevent this behaviour?
I know that some tables will not exist on one version of the DB, and I want to skip past those lines.
Many thanks,
Simon