Using WHERE and ORDER BY Clauses
Go Up to Using Select Procedures in isql
A SELECT
from a stored procedure can contain WHERE
and ORDER BY
clauses, just as in a SELECT
from a table or view.
The WHERE
clause limits the results returned by the procedure to rows matching the search condition. For example, the following statement returns only those rows where the HEAD_DEPT
is Sales and Marketing:
SELECT * FROM ORG_CHART WHERE HEAD_DEPT = 'Sales and Marketing';
The stored procedure then returns only the matching rows, for example:
HEAD_DEPT | DEPARTMENT |
MNGR_NAME |
TITLE |
EMP_CNT |
Sales and Marketing |
Pacific Rim Headquarters |
Baldwin, Janet |
Sales |
2 |
Sales and Marketing |
European Headquarters |
Reeves, Roger |
Sales |
3 |
Sales and Marketing |
Field Office: East Cost |
Weston, K. J. |
SRep |
2 |
The ORDER BY
clause can be used to order the results returned by the procedure. For example, the following statement orders the results by EMP_CNT, the number of employees in each department, in ascending order (the default):
SELECT * FROM ORG_CHART ORDER BY EMP_CNT;