You can use expression in select query in axapta following way.
LedgerTable LedgerTable ;
info(strfmt('%1',(select firstonly AccountNum from LedgerTable order by AccountNum desc
).AccountNum));