?
Solved

Joins? with Linked Server Tables

Posted on 2003-04-01
5
Medium Priority
?
295 Views
Last Modified: 2008-03-03
I am moving transactional data from our ERP (SAP) database to SQL Server (2K)for reporting purposes.  The idea is to keep the reporting load off the transactional system.  I am tring to keep the master data in SAP so I don't have to replicate all tables, just the big ones). I have set up a Linked server to the Oracel data.

I have a SQL Server (2K) table "custhist" with columns "custno" and "totalsales".

I have a linked server (Oracle/SAP) on the same server with table "custmaster" with columns "custno" and "custname" index on custno.

What is the best performing syntax to return all records from custhist for custno = "123" containing columns custno, custname and totalsales ?











0
Comment
Question by:sperry4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Expert Comment

by:RiverGuy
ID: 8247452
I worked with other linnked systems to SQL Server, but not Oracle.

You could do a pass-through query as:
SELECT * FROM OpenQuery(LinkedOracleServer, 'SELECT blah, blah')


Or, you could query it on SQL Server:
SELECT * FROM OracleServer.Database.Table


The syntax might have to be messed with.

You could also look into Microsoft Analysis Services if you did want to move some of the data over in the future for data mining.  It takes a bit of time to capture, massage and save the data, but the response time for browsing cubes and the like is almost instantaneous in some situations.
0
 

Author Comment

by:sperry4
ID: 8247582
looking for the exact syntax of the select statement that would join the SQL server table data to the linked server table data.

0
 
LVL 34

Accepted Solution

by:
arbert earned 400 total points
ID: 8249487
Like this--SQL Usually whines on 3part database names, so make sure you put a table alias on your linked oracle database in the from statement:


select * from custhist as SQLTable
inner join OracleServer.Database.Table as OracleTable
on  sqltable.custno=oracletable.custno
 and sqltable.totalsales=oracletable.totsales


Brett
0
 

Author Comment

by:sperry4
ID: 8255887
Sorry if I'm turning this into a new question but I believe the example query given will run slow (with out using index?).

I believe this to be true as when I run Query 1 below, it takes minutes versus the seconds Query 2 takes.  There is an ORACLE index on MANDT+VRGAR+RBLEN.

Is there a way to use OPENQUERY() in the example query given by arbert on 4/1 ?

Query 1
Select * from SAPLINKED..SAPR3.CE1MEDA AS X where X.MANDT='100' and X.VRGAR='F' and X.RBELN = '1014580858'

Query 2
Select * From OPENQUERY(SAPLINKED, "SELECT * from SAPR3.CE1MEDA where SAPR3.CE1MEDA.MANDT='100' and SAPR3.CE1MEDA.VRGAR='F' and SAPR3.CE1MEDA.RBELN = '1014580858'")



0
 
LVL 13

Expert Comment

by:ispaleny
ID: 8256638
Query 2 is run at server side, but there are some changes in SP3.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question