Joining Queries from Oracle and SQL Server Databases

Joining Queries from Oracle and SQL Server Databases

I need a query that retrieves info from an Oracle table and a query that retrieves info from a SQL Server table. The info has to be joined together according to Record ID numbers. I have very limited access to the Oracle database but full control of the SQL Server database.

How do I join two different queries from two different databases?

To query to different data sources, you can make the Oracle server a linked server to the SQL Server server. A linked server can be any OLE DB data source and SQL Server currently supports the OLE DB data provider for Oracle. You can add a linked server by calling sp_AddLinkedServer and query information about linked servers with sp_LinkedServers.

An easier way to add a linked server is to use Enterprise Manager. Add the server through the Linked Servers icon in the Security node. Once a server is linked, you can query it using a distributed query (you have to specify the full name).

Here’s an example of a distributed query (from the SQL Server Books Online) that queries the Employees table in SQL Server and the Orders table from Oracle:

SELECT emp.EmloyeeID, ord.OrderID, ord.DiscountFROM SQLServer1.Northwind.dbo.Employees AS emp,OracleSvr.Catalog1.SchemaX.Orders AS ordWHERE ord.EmployeeID = emp.EmployeeIDAND ord.Discount > 0

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist