Adding an ORDER BY Clause

Problem

You want to sort the output data in an SQL query that is included in a SAS Data Integration Studio job.

Solution

You can use the Order by tab in the Designer window to add an ORDER By clause to the SQL query.

Tasks

Add an ORDER BY Clause to an SQL Query in the Diagram Tab

You can add an ORDER BY clause to establish a sort order for the query results. Perform the following steps to add an ORDER BY clause to the SQL query in the Designer window:
  1. Click Create in the Navigate pane to access the Diagram tab and the SQL Clauses pane.
  2. Double-click Order by in the SQL Clauses pane. The Order by object is added to the query flow in the Diagram tab.
  3. Click the Order by object in the SQL Clauses pane to access the Order by tab.
  4. Select the column that you want to use for ordering the query results from the Available columns field. Then, move the column to the Order by columns field. Finally, enter a value in the Sort Order field to determine whether the results are sorted in ascending or descending order.
  5. The following display depicts a sample SQL query with an ORDER BY clause.
    Sample SQL Query Sorted with an ORDER BY Clause
    Sample SQL Query Sorted with an ORDER BY Clause
Note that the ORDER BY column is set on the Order by tab, and the resulting SQL code is highlighted on the Code tab. To highlight the code for a query object, right-click the object in the Navigate pane and click Find In. Then, click Code in the submenu.