On 23.10.2017 at 14:37, j...@acousticdesign.co.uk [firebird-support] wrote:
> I have a stored procedure along the lines of
>   SELECT ID, Amount1, Amount2 ..
>   FROM Table1.
>   UNION
>   SELECT ID, Amount1, Amount2...
>   FROM Table2
>   ORDER BY 1
>   Is it possible to construct a conditional ORDER By clause that orders by 
> Amount1 under certain conditions, and order by Amount2 under other conditions?
>   

Try something like this:

select iif(your condition, Amount1, Amount2) as SORTCOL, ID, Amount1, 
Amount2, ...
from Table1
union
select iif(your condition, Amount1, Amount2) as SORTCOL, ID, Amount1, 
Amount2, ...
from Table2
order by 1

If there are more than two possible candidates for the ordering column, 
you can switch from iif to case - when - end.

have a good one
Tomasz

-- 
__--==============================--__
__--==     Tomasz Tyrakowski    ==--__
__--==        SOL-SYSTEM        ==--__
__--== http://www.sol-system.pl ==--__
__--==============================--__
  • [firebird-... j...@acousticdesign.co.uk [firebird-support]
    • Re: [... Tomasz Tyrakowski t.tyrakow...@sol-system.pl [firebird-support]
      • R... j...@acousticdesign.co.uk [firebird-support]
    • Re: [... Helen Borrie hele...@iinet.net.au [firebird-support]
      • R... j...@acousticdesign.co.uk [firebird-support]
        • ... Svein Erling Tysvær setys...@gmail.com [firebird-support]

Reply via email to