Decode in order by - asc/desc

I'm trying to be able to dynamically change the asc/desc in the order by.
Here is some sql that works:
select * from transactions order by decode(somevar,'a',acct_nbr,'c',card_number,acct_nbr) asc
What I wanted was something like this:
select * from transactions order by decode(somevar,'a',acct_nbr,'c',card_number,acct_nbr) decode(anothervar,'a',asc,'d',desc,asc)
but this doesn't appear to work. Am I missing something, or is there another way.
Thanks in advance,

There are a bunch of restrictions on ordering when you use union all. It usually either requires the numerical position of the column, so if you want to order by the first column, then you order by 1, or a column alias, which sometimes can be used in only the first select and is sometimes required in all of them. However, even if you order by column position, such as order by 1, it does not seem to allow this in a decode. The simplest method is to use your entire query containing the union all as an inline view in an outer query. Please see the following examples that do this and also demonstrate how to get the order by options, including ascending and descending that you desire, assuming that your columns are of numeric data types.
scott@ORA92> -- sort by acct_nbr asc:
scott@ORA92> ACCEPT somevar PROMPT 'Enter a to sort by acct_nbr or c to sort by card_number: '
Enter a to sort by acct_nbr or c to sort by card_number: a
scott@ORA92> ACCEPT anothervar PROMPT 'Enter 1 to sort ascending or -1 to sort descending: '
Enter 1 to sort ascending or -1 to sort descending: 1
scott@ORA92> SELECT acct_nbr, card_number
  2  FROM   (SELECT 1     AS acct_nbr,
  3                3     AS card_number
  4            FROM   dual
  5            UNION ALL
  6            SELECT 2     AS acct_nbr,
  7                4     AS card_number
  8            FROM   dual
  9            UNION ALL
10            SELECT 3     AS acct_nbr,
11                2     AS card_number
12            FROM   dual
13            UNION ALL
14            SELECT 4     AS acct_nbr,
15                5     AS card_number
16            FROM   dual
17            UNION ALL
18            SELECT 5     AS acct_nbr,
19                1     AS card_number
20            FROM   dual)
21  ORDER  BY DECODE ('&somevar',
22                   'a', acct_nbr * NVL (&anothervar, 1),
23                   'c', card_number * NVL (&anothervar, 1),
24                   acct_nbr * NVL (&anothervar, 1))
25  /
  ACCT_NBR CARD_NUMBER
         1           3
         2           4
         3           2
         4           5
         5           1
scott@ORA92> -- sort by card_number asc:
scott@ORA92> ACCEPT somevar PROMPT 'Enter a to sort by acct_nbr or c to sort by card_number: '
Enter a to sort by acct_nbr or c to sort by card_number: c
scott@ORA92> ACCEPT anothervar PROMPT 'Enter 1 to sort ascending or -1 to sort descending: '
Enter 1 to sort ascending or -1 to sort descending: 1
scott@ORA92> SELECT acct_nbr, card_number
  2  FROM   (SELECT 1     AS acct_nbr,
  3                3     AS card_number
  4            FROM   dual
  5            UNION ALL
  6            SELECT 2     AS acct_nbr,
  7                4     AS card_number
  8            FROM   dual
  9            UNION ALL
10            SELECT 3     AS acct_nbr,
11                2     AS card_number
12            FROM   dual
13            UNION ALL
14            SELECT 4     AS acct_nbr,
15                5     AS card_number
16            FROM   dual
17            UNION ALL
18            SELECT 5     AS acct_nbr,
19                1     AS card_number
20            FROM   dual)
21  ORDER  BY DECODE ('&somevar',
22                   'a', acct_nbr * NVL (&anothervar, 1),
23                   'c', card_number * NVL (&anothervar, 1),
24                   acct_nbr * NVL (&anothervar, 1))
25  /
  ACCT_NBR CARD_NUMBER
         5           1
         3           2
         1           3
         2           4
         4           5
scott@ORA92> -- sort by acct_nbr desc:
scott@ORA92> ACCEPT somevar PROMPT 'Enter a to sort by acct_nbr or c to sort by card_number: '
Enter a to sort by acct_nbr or c to sort by card_number: a
scott@ORA92> ACCEPT anothervar PROMPT 'Enter 1 to sort ascending or -1 to sort descending: '
Enter 1 to sort ascending or -1 to sort descending: -1
scott@ORA92> SELECT acct_nbr, card_number
  2  FROM   (SELECT 1     AS acct_nbr,
  3                3     AS card_number
  4            FROM   dual
  5            UNION ALL
  6            SELECT 2     AS acct_nbr,
  7                4     AS card_number
  8            FROM   dual
  9            UNION ALL
10            SELECT 3     AS acct_nbr,
11                2     AS card_number
12            FROM   dual
13            UNION ALL
14            SELECT 4     AS acct_nbr,
15                5     AS card_number
16            FROM   dual
17            UNION ALL
18            SELECT 5     AS acct_nbr,
19                1     AS card_number
20            FROM   dual)
21  ORDER  BY DECODE ('&somevar',
22                   'a', acct_nbr * NVL (&anothervar, 1),
23                   'c', card_number * NVL (&anothervar, 1),
24                   acct_nbr * NVL (&anothervar, 1))
25  /
  ACCT_NBR CARD_NUMBER
         5           1
         4           5
         3           2
         2           4
         1           3
scott@ORA92> -- sort by card_number desc:
scott@ORA92> ACCEPT somevar PROMPT 'Enter a to sort by acct_nbr or c to sort by card_number: '
Enter a to sort by acct_nbr or c to sort by card_number: c
scott@ORA92> ACCEPT anothervar PROMPT 'Enter 1 to sort ascending or -1 to sort descending: '
Enter 1 to sort ascending or -1 to sort descending: -1
scott@ORA92> SELECT acct_nbr, card_number
  2  FROM   (SELECT 1     AS acct_nbr,
  3                3     AS card_number
  4            FROM   dual
  5            UNION ALL
  6            SELECT 2     AS acct_nbr,
  7                4     AS card_number
  8            FROM   dual
  9            UNION ALL
10            SELECT 3     AS acct_nbr,
11                2     AS card_number
12            FROM   dual
13            UNION ALL
14            SELECT 4     AS acct_nbr,
15                5     AS card_number
16            FROM   dual
17            UNION ALL
18            SELECT 5     AS acct_nbr,
19                1     AS card_number
20            FROM   dual)
21  ORDER  BY DECODE ('&somevar',
22                   'a', acct_nbr * NVL (&anothervar, 1),
23                   'c', card_number * NVL (&anothervar, 1),
24                   acct_nbr * NVL (&anothervar, 1))
25  /
  ACCT_NBR CARD_NUMBER
         4           5
         2           4
         1           3
         3           2
         5           1
[pre]

Similar Messages

  • Break Order Attribute (Asc/Desc) in Reports

    Please forgive me my ignorance.
    I have a dummy column that I use to select another column into. I set the break attribute on it as ascending.
    Now my user wants it either way i.e. ascending or descending.
    Is there way to change the break order attribute to change sorting dynamically depending on inputs.
    Thanks in advance to all who reply.

    I was hoping that someone would know how I can modify the
    ORDER BY 1 DESC,27 ASC part
    The ORDER BY 1 DESC,27 ASC part is generated by break attributes. I would like to modify the "DESC" dynamically from within the report so I could change it as needed.
    I don't know if it can be done via one of the srw package functions... and if so, which one and how. That was where I was trying to go.

  • Needs rows to be listed in BEX in a particular order(not asc desc)

    See the thread.
    Needs rows to be listed in a particular order(not ascending or descending)

    To create a hierarchy you can go in RSA1, infoobject tag, find your infoobject, double click on it and set the flag with hierarchy under Hierarchy tag; save and activate and exit.
    Than right click and choose 'Create hierarchy'.
    After creating hierarchy, in bex properties of the infoobject you can set it to use this hierarchy.
    For second question, if there's a logic to define sort order, while you are loading data, you can write a routine in update rules to populate a specific infoobject with a value for the sort.
    Hope now it's more clear.
    Regards

  • Decode in order by clause with desc

    I want to user order by clause with decode + desc order.
    somthing like
    ORDER BY DECODE ('SALE', e.sale, 'SALE DESC' ????)
    ????-> How to use desc order with decode
    Thanks in advance

    I thought smart people in this OTN community will understand that I am trying to order by the thisdate column that is timestamp datatype:). My apologize for not being that specific.
    The query I gave is a simple version of the stored procedure I am using. The point is I need to order by - depending on one of the parameters that is passed to the procedure. In simplest decode statements, its something like
    order by decode(p_in_var,'ABC','thisdate asc','DEF','thisdate desc',thisdate asc)
    Here p_in_var is varchar input parameter to the stored procedure.
    Please let me know if there is any more information needed.
    Thx!

  • Asc &Desc

    Hi! all
    i would appreciate if any one would clear me the concept of the
    order by clause using the ASC and DESC
    i have a table which has the few columns
    including the date the column as one of them
    Most of the Queires i deal with need to
    return the most recent records
    ( as each record entered today as date field entered ..today's date..)
    So...
    select * from
    <table_name>
    where rownnum <=10 **need to only first 10 records**
    order by datefiled desc
    hoping that i would get most recent at the top...
    but it falied...
    i tried with
    **Order by ASC*** it also returned same
    old ten records(1998) but not new(2000)
    Now i am confused with the concept of DESC/ASC
    does it work with DATE field...
    if not what would be best way to query the most recent records.(DATE FIELD)
    Experts please clarify my question ASAP
    Best Rgds
    null

    Hello Some,
    This type of subquery was first available in 7.3.4 (I think). You can find more about it in:
    Oracle8i SQL Reference
    Release 8.1.5
    Chapter 5 Expressions, Conditions, and Queries
    This type of subquery can be used instead of creating a view. You can also use it to bypass some limitations. A nice example is the CONNECT BY clause. When you use this, you have limitations. When you put the part with the CONNECT BY clause in such a subquery, you are able to do a lot more in this SQL-statement than otherwise.
    SELECT TRE.TREELEVEL, TRE.PARENTID, TRE.NODEID,
    DOC.URL, DOC.DESCRIPTION,
    NVL(IMG.CLOSEDIMAGE, nvl(IMG.OPENIMAGE, 'folder')) CLOSEDIMAGE,
    NVL(IMG.OPENIMAGE, 'folder') OPENIMAGE
    FROM (select level TREELEVEL, nod.documentid, nod.nodeid, nod.nodeseq, nod.parentid
    from web.nodes nod
    start with nod.nodeid=&TreeRoot
    connect by prior nod.nodeid=nod.parentid) TRE,
    WEB.DOCUMENTS DOC, WEB.IMAGES IMG
    WHERE TRE.DOCUMENTID=DOC.DOCUMENTID(+)
    AND DOC.IMAGEID =IMG.IMAGEID(+)
    ORDER BY DOC.DESCRIPTION
    null

  • Using Decode in Order By clause

    Hi all,
    I've a prblem with the DECODE in ORDER BY clause
    Could you please advise if I did something wrong with my sort order.
    Actually,I've a store procedure which gather all information from several tables and return with a resultset.
    Therefore I just post an example table_resultset instead of lenghthy StoreProc in forum
    /* table contain the column need to be sort on the resultset */
    create table table_sort (sortnum,sortname) as
    select 1553, 'IDNO' from dual union all
    select 1231, 'IDNAME' from dual union all
    select 1001, 'CREDATE' from dual;
    /* a sample of some information that resultset return by a storeproc */
    create table table_resultset (idno,idname,credate) as
    select 1111, 'SORT ORDER', sysdate-7 from dual union all
    select 54555, 'NEED A TEST CASE', sysdate+5 from dual union all
    select 10012, 'BEYOND THE LIMIT', sysdate from dual union all
    select 10522, 'CONCENTRATION', sysdate+20 from dual union all
    select 01231, 'A VALIDATION', sysdate-3 from dual;
    /* this select statement similar to execute a storeproc with s decode in the ORDER BY clause */
    select * from table_resultset
    order by decode((select ltrim(rtrim(sortname)) from table_sort where sortnum=1231),'IDNO',1,'IDNAME',2,3);
    OR
    select * from table_resultset
    order by case (select ltrim(rtrim(sortname)) from table_sort where sortnum=1231)
    when 'IDNO' then 1
    when 'IDNAME' then 2
    else 3
    end;
    Thanks.

    Thanks for the tip Samb ... :)
    I got it ... all sort field must be same datatype.
    SQL> create table table_sort (sortnum,sortname) as
    2 select 1553, 'IDNO' from dual union all
    3 select 1231, 'IDNAME' from dual union all
    4 select 1001, 'CREDATE' from dual;
    Table created.
    SQL> create table table_resultset (idno,idname,credate) as
    2 select 1111, 'SORT ORDER', sysdate-7 from dual union all
    3 select 54555, 'NEED A TEST CASE', sysdate+5 from dual union all
    4 select 10012, 'BEYOND THE LIMIT', sysdate from dual union all
    5 select 10522, 'CONCENTRATION', sysdate+20 from dual union all
    6 select 01231, 'A VALIDATION', sysdate-3 from dual;
    Table created.
    SQL> select * from table_resultset;
    IDNO IDNAME CREDATE
    1111 SORT ORDER 08-07-03
    54555 NEED A TEST CASE 08-07-15
    10012 BEYOND THE LIMIT 08-07-10
    10522 CONCENTRATION 08-07-30
    1231 A VALIDATION 08-07-07
    SQL> select * from table_sort;
    SORTNUM SORTNAM
    1553 IDNO
    1231 IDNAME
    1001 CREDATE
    if I want to sort the resultset by the column IDNAME of table_resultset then
    SQL> select * from table_resultset
    2 order by decode((select ltrim(rtrim(sortname)) from table_sort
    3 where sortnum=1231),'IDNO',to_char(idno),'IDNAME',idname,to_char(credate,'yyyymmdd'));
    IDNO IDNAME CREDATE
    1231 A VALIDATION 08-07-07
    10012 BEYOND THE LIMIT 08-07-10
    10522 CONCENTRATION 08-07-30
    54555 NEED A TEST CASE 08-07-15
    1111 SORT ORDER 08-07-03
    if I want to sort the resultset by the column CREDATE of table_resultset then
    SQL> select * from table_resultset
    2 order by decode((select ltrim(rtrim(sortname)) from table_sort
    3 where sortnum=1001),'IDNO',to_char(idno),'IDNAME',idname,to_char(credate,'yyyymmdd'));
    IDNO IDNAME CREDATE
    1111 SORT ORDER 08-07-03
    1231 A VALIDATION 08-07-07
    10012 BEYOND THE LIMIT 08-07-10
    54555 NEED A TEST CASE 08-07-15
    10522 CONCENTRATION 08-07-30
    But if I want to sort the resultset by the column IDNO of table_resultset then I've a problem due to the field converted into character, and the field IDNO define as number(9) of a table in production. therefore I've to find a solution when that field convert into character must be same length in order to sort IDNO correctly. As you can see from below
    SQL> select * from table_resultset
    2 order by decode((select ltrim(rtrim(sortname)) from table_sort
    3 where sortnum=1553),'IDNO',to_char(idno),'IDNAME',idname,to_char(credate,'yyyymmdd'));
    IDNO IDNAME CREDATE
    10012 BEYOND THE LIMIT 08-07-10
    10522 CONCENTRATION 08-07-30
    1111 SORT ORDER 08-07-03
    1231 A VALIDATION 08-07-07
    54555 NEED A TEST CASE 08-07-15
    your suggestion always welcome.
    Thanks,
    DT.

  • Order by rDate desc is not working

    Hello,
    order by rDate desc is not working in my following query
    select cv_id,to_char(rDate,'Month dd, yyyy') from jobResponses 
    where job_id=35 and (responseStatus=1 OR responseStatus=2) order by rDate desc
    March     03, 2012
    March     03, 2012
    March     04, 0012Thanks in anitcipation

    Christy H. wrote:
    order by rDate desc is not working in my following queryWell, it works just fine. Last rDate year is 0012, that's why it is the last one. It looks like table data wasn't loaded correctly and you ended up having rows with year 12 instead of 2012. Check table data.
    SY.

  • Order by date desc in oracle 10g

    hil all.
    i want to order the query by date desc but i want to retrieve only top 20 records according to date means latest how can i get,
    Thanks,

    Toon Koppelaars wrote:
    But of course you can use analytics too, which other posters will show you.Why not ;-)
    Depending on what OP want (Note that these does not return the same thing)
    SQL> select empno, ename, hiredate, rnk
      from (select emp.*, row_number() over (order by hiredate desc) rnk from emp)
    where rnk <= 5
         EMPNO ENAME      HIREDATE        RNK
          7698 BLAKE                        1
          7876 ADAMS      83-01-12          2
          7788 SCOTT      82-12-09          3
          7934 MILLER     82-01-23          4
          7900 JAMES      81-12-03          5
    5 rows selected.
    SQL> select empno, ename, hiredate, rnk
      from (select emp.*, dense_rank() over (order by hiredate desc) rnk from emp)
    where rnk <= 5
         EMPNO ENAME      HIREDATE        RNK
          7698 BLAKE                        1
          7876 ADAMS      83-01-12          2
          7788 SCOTT      82-12-09          3
          7934 MILLER     82-01-23          4
          7900 JAMES      81-12-03          5
          7902 FORD       81-12-03          5
    6 rows selected.Regards
    Peter

  • Non riesco a ricevere acquisti fatti su itunes, mi da questo errore :erreu : you have an error in your sql syntax; checkthe manual that corresponds to your mysql server version for the right syntax to use near from news order by id desc at line. cosa devo

    non riesco a ricevere acquisti fatti su itunes, mi da questo errore :erreu : you have an error in your sql syntax; checkthe manual that corresponds to your mysql server version for the right syntax to use near from news order by id desc at line. cosa devo fare?  grazie

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]

  • How to display result order by date desc?

    Hi Everyone,
    My DB version is
    BANNER                                                        
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
    PL/SQL Release 10.2.0.1.0 - Production                          
    CORE 10.2.0.1.0 Production                                        
    TNS for Linux: Version 10.2.0.1.0 - Production                  
    NLSRTL Version 10.2.0.1.0 - Production                          
    Please do have a look at this query and the result displayed. It's always showing results in draw_dt asc. I need to get this result as draw_dt desc. Please suggest something.
    select rownum as sl_no,
           sub.patient_name,
           sub.external_id,
           sub.modality,
           sub.account_number,
           sub.hlab_num,
           sub.spectra_mrn,
           sub.draw_dt,
           sub.requisition_number,
           sub.facility_name,
           sub.facility_id,
           sub.corporation_name,
           sub.acronym,
           sub.patient_id,
           SUB.TEST_ID,
           count(sub.requisition_number) over (partition by null) as entity_count
    from(
    select distinct
            (select p.last_name || ', ' || p.first_name
              from patient p
             where p.patient_id = loc.patient_id) as patient_name,
           (select p.external_id
              from patient p
             where p.patient_id = loc.patient_id) as external_id,
           (select p.spectra_mrn
            from patient p
            where p.patient_id = loc.patient_id) as spectra_mrn,
           ord.requisition_number as requisition_number,
           f.facility_name as facility_name,
           f.facility_id as facility_id,
           (select fad.account_type as modality
              from patient p,
                   patient_facility_modality pfm,
                   facility_account_modality fam,
                   facility_account_detail fad
             where p.patient_id = pfm.patient_id
               and pfm.facility_account_modality_id =
                                                  fam.facility_account_modality_id
               and fam.facility_account_detail_id = fad.facility_account_detail_id
               and p.patient_id = loc.patient_id
               and pfm.facility_id = loc.facility_id) as modality,
           (select fad.account_number as account_number
              from patient p,
                   patient_facility_modality pfm,
                   facility_account_modality fam,
                   facility_account_detail fad
             where p.patient_id = pfm.patient_id
               and pfm.facility_account_modality_id =
                                                  fam.facility_account_modality_id
               and fam.facility_account_detail_id = fad.facility_account_detail_id
               and p.patient_id = loc.patient_id
               and pfm.facility_id = loc.facility_id) as account_number,
           (select fad.hlab_num as hlab_num
              from patient p,
                   patient_facility_modality pfm,
                   facility_account_modality fam,
                   facility_account_detail fad
             where p.patient_id = pfm.patient_id
               and pfm.facility_account_modality_id =
                                                  fam.facility_account_modality_id
               and fam.facility_account_detail_id = fad.facility_account_detail_id
               and p.patient_id = loc.patient_id
               and pfm.facility_id = loc.facility_id) as hlab_num,
           loc.order_draw_dt as draw_dt,
           c.corporation_name as corporation_name,
           c.corporation_acronym as acronym,
           loc.patient_id,
           loct.test_id
      from lab_order_occ loc,
           lab_order_occ_test loct,
           facility f,
           corporation c,
           order_requisition_header ord
    where loc.lab_order_occ_id = loct.lab_order_occ_id
       and loc.facility_id = f.facility_id
       and f.corporation_id = c.corporation_id
       and ord.patient_id = loc.patient_id
       and ord.facility_id = loc.facility_id
       and ord.draw_dt = loc.order_draw_dt
       and loc.order_draw_dt between sysdate - 65 and sysdate
       and loc.status = 'A'
       and loc.msg_sent_to_lab_yn = 'Y'
       and loct.test_id in (
                       select test_id
                         from test_required
                        where required_test_code in (
                                                     select test_code
                                                       from interface_adt_aoe_master))
       and upper (c.corporation_acronym) in ('CORVA', 'DSI', 'USRC', 'DLYSNEWCO')
       and not exists (
                        select 1 from emr_adtaoe_dtl
                        where patient_id = loc.patient_id
                        and facility_id = loc.facility_id
                        and status = 'Y'
                        ))sub
    ORDER BY
            sub.draw_dt,
    --         sl_no,
             sub.corporation_name,
             sub.facility_name,
             SUB.PATIENT_NAME
             desc;
    Result
    SL_NO
    PATIENT_NAME
    EXTERNAL_ID
    MODALITY
    ACCOUNT_NUMBER
    HLAB_NUM
    SPECTRA_MRN
    DRAW_DT
    REQUISITION_NUMBER
    FACILITY_NAME
    FACILITY_ID
    CORPORATION_NAME
    ACRONYM
    PATIENT_ID
    TEST_ID
    ENTITY_COUNT
    9
    New, Pat
    123456
    HEMO
    72910
    A102805
    366999
    29-DEC-13
    9KT005A
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6181
    5558
    16
    2
    New, Pat
    123457
    HEMO
    72910
    A102805
    366999
    29-DEC-13
    9KT0057
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6181
    5558
    16
    7
    New, Pat
    123458
    HEMO
    72910
    A102805
    366999
    29-DEC-13
    9KT0059
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6181
    5558
    16
    16
    Erere, Gggg
    123459
    HEMO
    72910
    A102805
    622200
    29-DEC-13
    9KT0058
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    622
    5558
    16
    10
    Erere, Gggg
    123460
    HEMO
    72910
    A102805
    622200
    29-DEC-13
    9KT0056
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    622
    5558
    16
    1
    Test, Pat
    123461
    HEMO
    72910
    A102805
    367021
    30-DEC-13
    9KT0065
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6203
    5558
    16
    14
    Test, Pat
    123462
    HEMO
    72910
    A102805
    367021
    30-DEC-13
    9KT0064
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6203
    5558
    16
    4
    New, Pat
    123463
    HEMO
    72910
    A102805
    366999
    30-DEC-13
    9KT005W
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6181
    5558
    16
    3
    New, Pat
    123464
    HEMO
    72910
    A102805
    366999
    30-DEC-13
    9KT005X
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6181
    5558
    16
    8
    New, Pat
    123465
    HEMO
    72910
    A102805
    366999
    30-DEC-13
    9KT005V
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6181
    5558
    16
    13
    Test, Pat
    123466
    HEMO
    72910
    A102805
    367021
    01-JAN-14
    9KT006J
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6203
    5558
    16
    5
    Test, Pat
    123467
    HEMO
    72910
    A102805
    367021
    01-JAN-14
    9KT006G
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6203
    5558
    16
    6
    Test, Pat
    123468
    HEMO
    72910
    A102805
    367021
    01-JAN-14
    9KT006H
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6203
    5558
    16
    11
    Test, Pat
    123469
    HEMO
    72910
    A102805
    367021
    05-JAN-14
    9KT0077
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6203
    5558
    16
    15
    Test, Pat
    123470
    HEMO
    72910
    A102805
    367021
    05-JAN-14
    9KT0076
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6203
    5558
    16
    12
    New, Pat
    123471
    HEMO
    72910
    A102805
    366999
    06-JAN-14
    9KT0075
    DCI Freehold
    90
    DIALYSIS CLINIC, INC.
    DLYSNEWCO
    6181
    5558
    16
    See the date value for draw_dt column. It's always in asc order. How can I display this result set with draw_dt desc order? Please suggest something.

    ORDER BY  
            sub.draw_dt desc, 
    --         sl_no, 
             sub.corporation_name, 
             sub.facility_name, 
             SUB.PATIENT_NAME 
             desc;

  • How To Sort the Table Through Push Buttons (ASC & Desc)???

    Hi,
    I am facing a problem with regard to 'Push Buttons' that I have created on
    my Form. I want the 'Push Button' to sort the table with respect to a
    specific column in 'Ascending order' on first push and then in 'Descending
    order' on second push and then again in 'Ascending order' on third push and so
    on...
    please help me to achieve this
    regards,
    .

    Hello,
    You could try something like this:
    Declare
         LC$Order Varchar2(128) := Get_Block_Property( 'EMP', ORDER_BY ) ;
    Begin
         If Instr( LC$Order, 'DESC' ) > 1 Then
               Set_Block_Property( 'EMP', ORDER_BY, 'EMPNO ASC' ) ;
         Else
               Set_Block_Property( 'EMP', ORDER_BY, 'EMPNO DESC' ) ;
         End if ;
         Execute_Query ;
    End ;     Francois

  • Order by Asc question?

    I was wondering how you could do an asc by the third integer in a column
    Here is my code:
    order by decode(pitch_count,'First Pitch','0--','Full Count','999',pitch_count) asc;it order the pitch_count column like this:
    Pitch_Count
    First Pitch
    0-1
    0-2
    1-0
    2-0
    etc
    What I want
    Pitch Count
    First Pitch
    1-0
    2-0
    3-0
    0-1
    0-2
    etc

    Like this:
      1  with t as (select '0-1' pitch_count from dual
      2  union all select '0-2' from dual
      3  union all select '1-0' from dual
      4  union all select '2-0' from dual
      5  union all select '3-0' from dual
      6  union all select 'first pitch' from dual
      7  )
      8  select * from t
      9  order by to_number(substr(DECODE(pitch_count,'first pitch','0-0',pitch_count),1,1))
    10*         ,to_number(substr(DECODE(pitch_count,'first pitch','0-0',pitch_count),3,1))
    SQL>/
    PITCH_COUNT
    first pitch
    0-1
    0-2
    1-0
    2-0
    3-0included "first pitch"

  • How to display  Columns  in Alphabatical  order when using DESC command

    Hello
    A table column is inserted not in alphabetic order during the table creation definition.
    So while describing the table definition (e.g. desc emp)
    it will not show in the same order as we are written during the table creation.
    Question: is there any utility/command/query which will display the columns in alphabatical order while describing it.
    Regards
    Nikhil Wani

    select column_name from user_tab_columns
    order by column_name;
    should do it.
    Sunil

  • Decode in order by clause

    Is it possible to use a decode function in the order by clause, when you have two select statements with a union between? I seem to be getting an error-message telling me to type a number.
    Can anybody help me?

    Tove,
    Is this what you mean?
    SQL> SELECT
      2  *
      3  FROM
      4  (SELECT
      5      empno     no
      6  ,   ename     name
      7  ,   job       description
      8  FROM          emp
      9  UNION
    10  SELECT
    11      deptno    no
    12  ,   dname     name
    13  ,   loc       description
    14  FROM          dept
    15  )
    16  ORDER BY
    17  DECODE(1
    18  ,      1,TO_CHAR(no)
    19  ,      2,name
    20  ,      3,description)
    21  /
            NO NAME           DESCRIPTION
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
          7369 SMITH          CLERK
          7499 ALLEN          SALESMAN
          7521 WARD           SALESMAN
          7566 JONES          MANAGER
          7654 MARTIN         SALESMAN
          7698 BLAKE          MANAGER
          7782 CLARK          MANAGER
          7788 SCOTT          ANALYST
          7839 KING           PRESIDENT
          7844 TURNER         SALESMAN
          7876 ADAMS          CLERK
          7900 JAMES          CLERK
          7902 FORD           ANALYST
          7934 MILLER         CLERK
    18 rows selected.Now, to order by the second column, I set the first parameter of the
    DECODE to "2":
    SQL> SELECT
      2  *
      3  FROM
      4  (SELECT
      5      empno     no
      6  ,   ename     name
      7  ,   job       description
      8  FROM          emp
      9  UNION
    10  SELECT
    11      deptno    no
    12  ,   dname     name
    13  ,   loc       description
    14  FROM          dept
    15  )
    16  ORDER BY
    17  DECODE(2
    18  ,      1,TO_CHAR(no)
    19  ,      2,name
    20  ,      3,description)
    21  /
            NO NAME           DESCRIPTION
            10 ACCOUNTING     NEW YORK
          7876 ADAMS          CLERK
          7499 ALLEN          SALESMAN
          7698 BLAKE          MANAGER
          7782 CLARK          MANAGER
          7902 FORD           ANALYST
          7900 JAMES          CLERK
          7566 JONES          MANAGER
          7839 KING           PRESIDENT
          7654 MARTIN         SALESMAN
          7934 MILLER         CLERK
            40 OPERATIONS     BOSTON
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
          7788 SCOTT          ANALYST
          7369 SMITH          CLERK
          7844 TURNER         SALESMAN
          7521 WARD           SALESMAN
    18 rows selected.
    SQL> SELECT
      2  *
      3  FROM
      4  (SELECT
      5      empno     no
      6  ,   ename     name
      7  ,   job       description
      8  FROM          emp
      9  UNION
    10  SELECT
    11      deptno    no
    12  ,   dname     name
    13  ,   loc       description
    14  FROM          dept
    15  )
    16  ORDER BY
    17  DECODE(3
    18  ,      1,TO_CHAR(no)
    19  ,      2,name
    20  ,      3,description)
    21  /
            NO NAME           DESCRIPTION
          7788 SCOTT          ANALYST
          7902 FORD           ANALYST
            40 OPERATIONS     BOSTON
            30 SALES          CHICAGO
          7369 SMITH          CLERK
          7934 MILLER         CLERK
          7900 JAMES          CLERK
          7876 ADAMS          CLERK
            20 RESEARCH       DALLAS
          7566 JONES          MANAGER
          7698 BLAKE          MANAGER
          7782 CLARK          MANAGER
            10 ACCOUNTING     NEW YORK
          7839 KING           PRESIDENT
          7499 ALLEN          SALESMAN
          7844 TURNER         SALESMAN
          7654 MARTIN         SALESMAN
          7521 WARD           SALESMAN
    18 rows selected.I needed to put the TO_CHAR in the DECODE so all of the columns
    by which I could potentially order are VARCHAR2's, else I was
    getting
    SQL> /
    DECODE(1
    ERROR at line 17:
    ORA-01785: ORDER BY item must be the number of a SELECT-list expressionHTH
    T.

  • How to show values with initial sort asc/desc in 11.5.10 iProcurement page?

    (Logged Bug 12902576 with OAFramework DEV, but OAF DEV closed the bug and advised to log the issue here in the forum)
    How to have values sorted in ascending order when user first navigates to the page?
    Currently the values are unsorted, and are only sorted after the user clicks the column heading to sort the values. We expect the users should not have to click the column heading, but instead that the values should be sorted in ascending order when the user navigates to the page. This issue occurs on an OAFramework based page in iProcurement application.
    PROBLEM STATEMENT
    =================
    Receipts and Invoices are not sorted in iProcurement Lifecycle page even after implementing personalization to sort ascending on Receipt Number and Invoice Number. Users expect the receipts and invoices to be sorted but they are not sorted.
    STEPS TO REPRODUCE
    1. Navigate to iProcurement
    2. Click the Requisitions tab
    3. Search and find a requisition line that is associated to a Purchase Order having multiple receipts and multiple invoices.
    4. Click the Details icon to view the lifecycle page where the receipts and invoices are listed
    - see that the receipts are not sorted, and the invoices are not sorted
    5. Implement personalization to sort in ascending order for Receipt Number and for Invoice Number. Apply the personalization and return to page.
    - the receipts and invoices are still not sorted.
    IMPACT
    Users need the receipts and invoices sorted to make it easier to review the data. As a workaround, click the column heading to sort the results
    Tried workaround suggested by OAFramework DEV in Bug 12902576 but this did not help.
    TESTCASE of suggested workaround
    NAVIGATION in visprc01
    1. Login: dfelton / welcome
    2. iProcurement responsibility / iProcurement Home Page / Requisitions tab
    3. Click the Search button in the upper right
    4. Specify search criteria
    - Remove the 'Created by' value
    - Change 'Last 7 Days' to 'Anytime'
    - Type Requisition = 2206
    5. Click Go to execute the search
    6. Click the Requisition 2206 number link
    7. Click the Details icon
    8. In the Receipt section, click the link 'Personalize Table: (ReceivingTableRN)'
    9. Click the Personalize (pencil) icon
    10. Click the Query icon for Site level (looks different than the screenshots from OAFramework team, because this is 11.5.10 rather than R12
    - Compare this to the Table personalization page show in the reference provided by OAFramework team -
    http://www-apps.us.oracle.com/fwk/fwksite/jdev/doc/devguide/persguide/T401443T401450.htm#cust_persadmin_editperprop
    11. See on the Create Query page
    Sorting
    No sorting is allowed
    The Query Row option becomes available in personalize after setting the Receipt Number row to Searchable. However, even after clicking the Query icon to personalize, it is not possible to specify sorting. There is a Sorting heading section on the personalization page, but there is also a statement: No sorting is allowed
    The workaround mentioned by OAFramework team in Bug 12902576 does not work for this case
    - maybe because this is 11.5.10 rather than R12?
    - maybe similar to Bug 8351696, this requires extension implementation?
    What is the purpose of offering ascending/descending for Sort Allowed if it does not work?
    Please advise if there is a way to have the initial sort in ascending order for this page.

    I´m sorry that you couldn´t reproduce the problem.
    To be clear:
    It´s not about which symbol should seperate the integer part from the fraction.
    The problem is, that i can´t hide the fraction in bargraph.
    The data im showing are integers but the adf bar graph component wants to show at least 4 digits.
    As I´m from germany my locale should be "de" but it should matter in the test case.
    You can download my test case from google drive:
    https://docs.google.com/open?id=0B5xsRfHLScFEMWhUNTJsMzNNUDQ]
    If there are problems with the download please send me an e-mail: [email protected]
    I uploaded another screenshot to show the problem more clear:
    http://s8.postimage.org/6hu2ljymt/otn_hide_fraction.jpg
    Edited by: ckunzmann on Oct 26, 2012 8:43 AM

Maybe you are looking for

  • A gloom outlook on the fut

    To me this is a very simple situation. A. I bought the best product CL had to offer for a hefty sum of money, just a few months ago (X-Fi Elite Pro). B. At that time CL was communicating that drivers would be ready for Vista in time for the "official

  • External monitor not recognized (X200)

    Hi, I have an X200 with Vista When I connect an external monitor (or projector) it is not recognized.  Shift-F7 results in a message that no external monitor is detected.  However, if I leave the monitor connected, put the system in standby and then

  • Disappearing footers in PDF generated from FrameMaker 9

    Myself and three other writers are having a problem with disappearing footers in FrameMaker.  Here's the problem:  In FrameMaker, the footers display correctly.  When we convert a book to PDF, many of the footers disappear.  What we find is that a fo

  • Speaker Docks 100% Compatible With iPhone 3G?

    Are there ANY speaker docks that are truly 100% compatible with the iPhone 3G? Speaker docks that will charge the iPhone 3G WITHOUT a USB connection, won't keep offering to put the iPhone 3G in Airplane mode, and will play music without any interfere

  • Creating a photo collage on a Mac

    Hi. I'm relatively new to Mac and iPhoto. Is there a way to create a collage of say 15 or 16 pictures so I can print it out as a poster? I know Roxio has a photo program for Windows. Is there an equivalent for Mac? Thank you.