Insert into table on the Linked Server with data from local table
Correct syntax
INSERT OPENQUERY(sql_server, 'SELECT a1,a2,a3 FROM database.schema.table_a') (a1, a2, a3)SELECT b1, b2, b3 FROM database.schema.table_b;
It is normal that it doesn't work with an openquery. To write into a remote table, you must setup the linked server at your server level. This works with oracle, unless you have a sql version that is waaaay to old. Here is the way to setup the linkedserver at server side:
exec master.dbo.sp_MSset_oledb_prop 'ORAOLEDB.Oracle', N'AllowInProcess', 1goexec sp_addlinkedserver @server = 'MyOracleServer', @srvproduct = 'Oracle', @provider = 'OraOLEDB.Oracle', @datasrc = 'MyOracleLinkedServer'goexec master.dbo.sp_serveroption @server=N'MyOracleServer', @optname=N'rpc out', @optvalue=N'true'gosp_addlinkedsrvlogin @rmtsrvname = N'MyOracleServer', @useself = 'false', @locallogin = NULL, @rmtuser = 'myRemoteUser', @rmtpassword ='myRemotePassword'go
Then you can proceed with regular queries:
insert into [MyOracleServer]..[MyRemoteSchema].[MyRemoteTable]( [MyRemoteField1], [MyRemoteField2])select t.Field1, t.Field2from [dbo].[MyLocalTable] as t
If you want to go in more details here are two links you want to see:https://www.mssqltips.com/sqlservertip/4396/creating-a-sql-server-2014-linked-server-for-an-oracle-11g-database/
You should be able to use the linked server name as part of qualifying your table name, and then just do a normal insert into select:
INSERT INTO ORTEST.[dbname].[dbo].[reservation]SELECT * from [dbname].[db].[reservation]