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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

854 Querying Multiple DBMS Tables 4 Chapter 29Querying Multiple DBMS TablesYou can also retrieve data from multiple DBMS tables in a single query by using theSQL procedure. This example joins the Oracle tables Staff and Payroll to query salaryin<strong>for</strong>mation <strong>for</strong> employees who earn more than $40,000.libname mydblib oracle user=testuser password=testpass;title ’Employees with salary greater than $40,000’;options obs=20;proc sql;select a.lname, a.fname, b.salary<strong>for</strong>mat=dollar10.2from mydblib.staff a, mydblib.payroll bwhere (a.idnum eq b.idnum) and(b.salary gt 40000);quit;Note: By default, <strong>SAS</strong>/<strong>ACCESS</strong> passes the entire join to the DBMS <strong>for</strong> processing inorder to optimize per<strong>for</strong>mance. See “Passing Joins to the DBMS” on page 43 <strong>for</strong> morein<strong>for</strong>mation. 4Output 29.8Querying Multiple Oracle TablesEmployees with salary greater than $40,000LNAME FNAME SALARY--------------------------------------------WELCH DARIUS $40,858.00VENTER RANDALL $66,558.00THOMPSON WAYNE $89,977.00RHODES JEREMY $40,586.00DENNIS ROGER $111379.00KIMANI ANNE $40,899.00O’NEAL BRYAN $40,079.00RIVERS SIMON $53,798.00COHEN LEE $91,376.00GREGORSKI DANIEL $68,096.00NEWKIRK WILLIAM $52,279.00ROUSE JEREMY $43,071.00The next example uses the SQL procedure to join and query the DB2 tables March,Delay, and Flight. The query retrieves in<strong>for</strong>mation about delayed international flightsduring the month of March.libname mydblib db2 ssid=db2;title "Delayed International Flights in March";proc sql;select distinct march.flight, march.dates <strong>for</strong>mat datetime9.,delay <strong>for</strong>mat=2.0from mydblib.march, mydblib.delay,mydblib.internat

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

Saved successfully!

Ooh no, something went wrong!