Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Kristen
Test
22859 Posts |
Posted - 2005-08-17 : 10:29:41
|
| I want to transfer new and modified data [there is an Update Date column available] from a local table into an identical table on a remote server.The intended process is to transfer first to a temporary [Staging] table (on the remote)Then (at the remote server) pre-delete any rows, and insert all the data from the Staging table into the Master tableI want to do something likeSELECT *INTO RemoteServer.RemoteDatabase.dbo.RemoteStagingFROM LocalDatabase.dbo.LocalMasterbut that's not allowed (max. 2 part name on the INTO bit)So I thought I'd create the table first using OPENQUERY or somesuchSELECT @strSQL = 'SELECT *FROM OPENQUERY(RemoteServer, ''SELECT * INTO RemoteDatabase.dbo.RemoteStagingFROM RemoteDatabase.dbo.RemoteMasterWHERE 1=0'')'EXEC (@strSQL)That gives:The OLE DB provider 'SQLOLEDB' indicates that the object has no columns.OLE DB error trace [Non-interface error: OLE DB provider unable to process object, since the object has no columnsProviderName='SQLOLEDB', Query=......]Any ideas please?Kristen |
|
|
VladRUS.ca
Starting Member
23 Posts |
Posted - 2005-08-17 : 14:00:08
|
| Your variant:================================DECLARE @strSQL nvarchar(1000)SELECT @strSQL = 'SELECT *FROM OPENQUERY(RemoteServer, ''SET NOCOUNT ONSET IMPLICIT_TRANSACTIONS OFFIF OBJECT_ID(''''RemoteDatabase.dbo.RemoteStaging'''', ''''U'''') > 0 DROP TABLE RemoteDatabase.dbo.RemoteStagingSELECT * INTO RemoteDatabase.dbo.RemoteStagingFROM RemoteDatabase.dbo.RemoteMasterWHERE 1=0SELECT @@ERROR AS ErrorCode'')'EXEC (@strSQL)goAlternative variant:================================EXEC sp_serveroption N'RemoteServer', N'rpc out', N'true'goDECLARE @strSQL nvarchar(1000)SELECT @strSQL = 'IF OBJECT_ID(''RemoteDatabase.dbo.RemoteStaging'', ''U'') > 0 DROP TABLE RemoteDatabase.dbo.RemoteStagingSELECT * INTO RemoteDatabase.dbo.RemoteStagingFROM RemoteDatabase.dbo.RemoteMasterWHERE 1=0'EXEC RemoteServer...sp_executesql @strSQL |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-08-17 : 14:19:14
|
| "EXEC RemoteServer...sp_executesql @strSQL"<thumps forehead>Well knock me down with a feather.I'm very grateful and if, as it looks like that's your first post, you registered especially to type that reply then I just don't know what to say!ThanksKristen |
 |
|
|
|
|
|