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.

Accessing DBMS Data with the SQL Pass-Through Facility 4 Using a Pass-Through Query in a Subquery 871Using a Pass-Through Query in a SubqueryThe following example shows how to use a subquery that contains a Pass-Throughquery. A subquery is a nested query and is usually part of a WHERE or HAVINGclause. Summary functions cannot appear in a WHERE clause, so using a subquery isoften a good technique. A subquery is contained in parentheses and returns one ormore values to the outer query <strong>for</strong> further processing.This example creates an SQL view, Samples.AllEmp, based on Sybase data. Sybaseobjects, such as table names and columns, are case sensitive. Database identificationstatements and column names are converted to uppercase unless they are enclosed inquotation marks.The outer PROC SQL query retrieves data from the SQL view; the subquery uses aPass-Through query to retrieve data. This query returns the names of employees whoearn less than the average salary <strong>for</strong> each department. The macro variable, Dept,substitutes the department name in the query.libname mydblib sybase server=server1 database=personneluser=testuser password=testpass;libname samples ’your-<strong>SAS</strong>-data-library’;/* Create SQL view */proc sql;create view samples.allemp asselect * from mydblib.employees;quit;/* Use the SQL pass-through facility to retrieve data */proc sql stimer;title "Employees Who Earn Below the &dept Average Salary";connect to sybase(server=server1 database=personneluser=testuser password=testpass);%put &sqlxmsg;%let dept=’ACC%’;select empid, lastnamefrom samples.allempwhere dept like &dept and salary

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

Saved successfully!

Ooh no, something went wrong!