Query from SQL Server tables in Oracle using ODI - sql-server

I have a database in Oracle and a database in SQL Server.
I want to write a query in Oracle and I need to use one of SQL Serever table in it.
Before I used database link but now I must to do this with ODI (Oracle Data Integrator).
The way I used before:
CREATE PUBLIC DATABASE LINK "DBLINK"
CONNECT TO "MatrisApp" IDENTIFIED BY VALUES ':1'
USING 'dg4msql';
INSERT
INTO everyday_deposit_temp ***/*this is a table in oracle*/***
(
"DEP_ID",
"REF_DEPOSIT_TYPE",
"REF_DEPOSIT_SUB_TYPE",
"LEDGER_CODE_SELF"
)
SELECT "DEP_ID",
"REF_DEPOSIT_TYPE",
"REF_DEPOSIT_SUB_TYPE",
"LEDGER_CODE_SELF"
FROM dbo.vw_deposit_changed#dblink
Please help me with this

The most common way to get data from MS SQL Server to Oracle through ODI is to use LKM MSSQL to ORACLE (BCP SQLLDR).
Now if you really want to use a dblink, I would try this approach:
Duplicate a Oracle IKM you want to use
In the definition tab, check the Multi-Connections checkbox and set Microsoft SQL Server for the Source Technology.
In the Options tab, add a new option DBLINK_NAME with Value type.
In the Tasks tab, find the task responsible of the insert and edit the target command to add this after the table name : #<%=odiRef.getOption("DBLINK_NAME")%>
Create a mapping using the new IKM. In the Physical tab, click on the target table and add the dblink name in the Option.

Related

How to automatically execute "create table" statements generated with select statement?

I have to move some data from our remote customer's mssql database to remote db2 database. On mssql server I own I created linked server to customer's source mssql database (I only have read permissions on) and created another linked server to remote db2 server.
I created some complex transformation, but for simplicity of this forum, lets simplify:
select
'create table [remotedb2server].[remotedb2db].[myschema].'
+ name
+ "COLUMS HERE AND SOME COMPLEX TRANSFORMATION"
from [remotemssqlserver].[remotemssql].[sys].[tables]
How to automatically execute above "create table" statements generated from select statement? I need a solution to be able to schedule it regularly in e.g. SQL Agent job.
I also have "drop table" select, "insert into" select etc and I would like to use the same logic.
This is known as dynamic SQL. You can execute arbitrary generated SQL by calling sp_executesql and passing in your command as a parameter. Keep in mind this has the potential to be very dangerous, as it exposes you to sql injection vulnerabilities.

Export from Access .mdb database with ODBC link to SQL Server into Access format database using VBA

I have an Access 2019 front-end database that links to a SQL Server 2017 Express database.
I'd like to export a table or query from the VBA code in the front-end into an Access (Jet) format database (as a portable data format to use for updating a remote site)
The code I've tried (for a table called FileLocation) is:
Access.DBEngine.CreateDatabase "C:\Temp\ExportTest3.mdb", DB_LANG_GENERAL
docmd.TransferDatabase transfertype:=acExport, databasetype:="Microsoft Access",databasename:="c:\temp\ExportTest3.mdb", objecttype:=acTable, source:="FileLocation", destination:="FileLocation", structureonly:=false
This "works" but the table created in the ExportTest3 database is a link to the SQL database (with the Connect property set in MSysObjects) so is dependant on the SQL Server connection, but I'm looking for an independant portable .mdb file that can be read on any PC.
Edit: I've discovered that I can use
docmd.RunSQL "select * into FileLocationLocal from FileLocation"
and then use TransferDatabase to export the FileLocationLocal table as a non-linked table
But is there a way to do this as a single step, or is there a better approach?
Consider:
Access.DBEngine.CreateDatabase "C:\Temp\ExportTest3.mdb", DB_LANG_GENERAL
CurrentDb.Execute "SELECT FileLocation.* INTO FileLocation IN 'C:\Temp\ExportTest3.mdb' FROM FileLocation"

How to copy data from a view of one server into the database table of another server in a SQL server database?

how can i copy data from a view of one server into the database table of another server in a SQL server database without using linked servers method.
I tried using the code:
SELECT [LogEntryID]
,[TimeStamp]
Into [server-2].[database1].[dbo].[table1]
FROM [server-1].[database1].[dbo].[view_1]
I recieve the error " The object name 'server-2.database1.dbo.table1' contains more than the maximum number of prefixes. The maximum is 2.
The copying statement i am using in a groovy code. But for first i am trying it in a query if it works.
You can use opendatasource instead of linked server
insert DestinationTable
select * from opendatasource('SQLOLEDB', 'Server=SourceServer;User Id=Username;Password=Password;').SourceDb.Schema.SourceTable;
OPENDATASOURCE

Query database running on another physical SQL Server

Historically we have a product which installed two databases on the same server. There is an custom application which assumes that both databases are on the same server.
In a new version they have split the databases onto two separate servers and obviously now the custom application is giving the error:
Database 'DB_2' does not exist. Make sure that the
name is entered correctly.
Is there anything I can do in the SQL Server setup so that the application is still able to query the DB_2 database without modifying the custom application?
The query being used is structured as follows:
Use DB_2
SELECT * FROM MyUser.MyTable
You can create a linked Server, then Create a Database DB_2 add a Synonym for different objects. something like below.
use master
GO;
EXEC master.dbo.sp_addlinkedserver #server = N'RemoteServer', #srvproduct=N'SQL Server'
GO
CREATE DATABASE [DB_2];
GO
USE [DB_2]
GO
CREATE SYNONYM [MyUser].[MyTable] FOR [RemoteServer].[db].[MyUser].[MyTable]
GO
You can use Linked Servers feature. In SSMS go to Server Object/Linked Servers folder in Object Explorer. And link second server. So you can query another DB using this SELECT * FROM [Linked_Server_Name].[Database_Name].[Schema_Name].[Table_Name]

From SQL Server how do I read from an MS Access database to UPDATE data in one or more table columns?

My SQL Server database table has a column that needs to be Updated with data from an MS Access file. How do I query the MS Access data to perform such an update?
Import Wizard seems to only handle Inserting of new data and not UPDATE existing data? Or am I misunderstanding how to use the wizard?
Sounds like you want to run that operation from the SQL Server side ... "pull" the Access data into SQL Server. If so, you can set up the Access file as a linked server within SQL Server. I've not done that, but have read cases where other people have. I copied these steps from How can I link a SQL Server database to MS Access using link tables in MS Access? at SQLServerPedia.
1) Open EM.
2) Goto the Server to which you want to add it as linked server.
3) Then goto security > Linked Servers section from console tree.
4) Right click on the Client area. Then New Linked Server.
5) Give a name and Specify Microsoft Jet 4.0 as Provider string.
6) Provide the location of the MDB file.
7) Click OK.
Alternatively, you could run the operation from the Access side, and push the data to SQL Server. If that could work for you, use Olivier's instructions to set up the ODBC-linked SQL Server table. Or you do it without creating a DSN: Using DSN-Less Connections.
Either way you link the table, the UPDATE statement you run from within Access might then be as simple as:
UPDATE
linked_table AS dest
INNER JOIN local_table AS src
ON dest.pkey_field = src.pkey_field
SET dest.access_data = src.access_data
WHERE
dest.access_data <> src.access_data
OR dest.access_data Is Null;
First set up a ODBC DSN in Windows. Open Control Panel > Administrative Tools > Data Sources (ODBC). Note that on 64 bit Windows, this might open the 64-bit-administrator. However, if you have a 32-bit Access, you need the 32-bit-administrator (%windir%\SysWOW64\odbcad32.exe).
Then you can link the SQL-Server tables to your access db. In the Link Tables dialog, choose "ODBC Databases()" as file type.
You can then query the linked SQL Server tables as if they were access tables.
See Configure Microsoft Access Linked Tables with a SQL Server Database

Resources