I had to do the following things copied from general-comments/www/index.tcl to make it work:
Add paramter -Torderby orderby to the ad_table call.
Put the table definition in a variable table_def
And add this to the end of my query in the XQL file:
[ad_order_by_from_sort_spec $orderby $table_def]
So it works, but I am not sure if there is a nicer way to make it work.