Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Joins? with Linked Server Tables

Posted on 2003-04-01
5
Medium Priority
?
297 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
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

577 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