13.07.2015 Views

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

44 Passing Joins to the DBMS 4 Chapter 5clauses be<strong>for</strong>e trying to pass the join to the DBMS. This can result in queriesnot being passed to the DBMS if they include additional WHERE clauses orcontain complex join conditions.For In<strong>for</strong>mix, outer joins can neither consist of more than two tables nor containa WHERE clause.Sybase evaluates multijoins with WHERE clauses differently than <strong>SAS</strong>.There<strong>for</strong>e, instead of passing multiple joins or joins with additional WHEREclauses to the DBMS, use the <strong>SAS</strong>/<strong>ACCESS</strong> DIRECT_SQL= LIBNAMEoption“DIRECT_SQL= LIBNAME Option” on page 143 to allow PROC SQL toprocess the join internally.Note: If PROC SQL cannot successfully pass down a complete query to the DBMS,it might try again to pass down a subquery. You can analyze the SQL that ispassed to the DBMS by turning on <strong>SAS</strong> tracing options. The <strong>SAS</strong> trace in<strong>for</strong>mationdisplays the exact queries that are being passed to the DBMS <strong>for</strong> processing. 4In this example, two large DBMS tables named TABLE1 and TABLE2 have a columnnamed DeptNo, and you want to retrieve the rows from an inner join of these tableswhere the DeptNo value in TABLE1 is equal to the DeptNo value in TABLE2. PROCSQL detects the join between two tables in the DBLIB library (which references anOracle database), and <strong>SAS</strong>/<strong>ACCESS</strong> passes the join directly to the DBMS. The DBMSprocesses the inner join between the two tables and returns only the resulting rows to<strong>SAS</strong>.libname dblib oracle user=testuser password=testpass;proc sql;select tab1.deptno, tab1.dname fromdblib.table1 tab1,dblib.table2 tab2where tab1.deptno = tab2.deptno;quit;The query is passed to the DBMS and generates this Oracle code:select table1."deptno", table1."dname" from TABLE1, TABLE2where TABLE1."deptno" = TABLE2."deptno"In this example, an outer join between two Oracle tables, TABLE1 and TABLE2, ispassed to the DBMS <strong>for</strong> processing.libname myoralib oracle user=testuser password=testpass;proc sql;select * from myoralib.table1 right join myoralib.table2on table1.x = table2.xwhere table2.x > 1;quit;The query is passed to the DBMS and generates this Oracle code:select table1."X", table2."X" from TABLE1, TABLE2where TABLE1."X" (+)= TABLE2."X"and (TABLE2."X" > 1)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!