Results 1 to 1 of 1
  1. #1
    Join Date
    Dec 2002

    Exclamation Unanswered: Disregard - found answer - order by a "select as" determined by case statement

    Disregard, found the answer.

    I decided to create a function to handle this due to time contraints. However, if anyone does have a solution for this, I would be still like to see it for future reference.

    Thank you.

    I'm not a db guru by any means so please forgive me if this has an easy solution.


    Want to sort by an alias for SELECT AGE(). Problem is the timestamps for the SELECT AGE will be determined by the value of another column, thus the use of CASE.

    What I thought would work.

    SELECT tblticket.ticketid,tblstatus.statusname,
    CASE WHEN tblstatus.statusname = 'Closed'
    THEN (SELECT AGE(tblticket.ticketclosed,tblticket.ticketcreated ) as ticketage)
    ELSE (SELECT AGE(CURRENT_TIMESTAMP,tblticket.ticketcreated) as ticketage)
    FROM tblticket CROSS JOIN tblstatus
    WHERE (tblticket.reasonid = 2) AND blah, blah, blah
    ORDER BY ticketage ASC

    CASE apparently completely ignores the ticketage alias. Anyone know how to get around this?

    Thank You.
    Last edited by fattony; 12-06-02 at 16:29.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts