one of the documented procedures in this installation of the ACS
ad_table_orderby_sql   datadef   orderby   order
What it does:
create the order by clause consistent with the orderby and order variables and the datadef which built the table
Defined in: /web/philip/packages/acs-core/table-display-procs.tcl

Source code:

    set orderclause "order by $orderby $order"
    foreach col $datadef {
        if {[string compare $orderby [lindex $col 0]] == 0} {
            if {![empty_string_p [lindex $col 2]]} {
                set orderclause [subst [lindex $col 2]]
    return $orderclause