Results 1 to 3 of 3

Thread: Order By

  1. #1
    Join Date
    Jun 2003
    Posts
    294

    Unanswered: Order By

    Hello, I have this Query and that result. I need to have the same result but First those which have Febaja Null, just moving the order by clause.


    SELECT CDACCION,
    DSACCION,
    TO_CHAR(FEALTA,'YYYY/MM/DD') FEALTA,
    TO_CHAR(FEBAJA,'YYYY/MM/DD') FEBAJA
    FROM TSIC_CORR_ACCIONESOP
    ORDER BY DECODE (FEBAJA,NULL,'FEBAJA DESC,DSACCION ASC', 'DSACCION DESC') NULLS FIRST



    CDACCION DSACCION FEALTA FEBAJA
    ======== ============ ==========
    7 ASDASDASD 2004/02/16 2004/02/16
    8 ASDASDADS 2004/02/16 2004/02/16
    10 2382 2004/02/16 2004/02/16
    1 IMPRIMIR 2003/12/04 {null}
    2 ENVIAR 2003/12/04 {null}
    3 LLAMADA 2003/12/04 {null}
    9 NUEVO 2004/02/16 {null}
    4 RECIBIR 2003/12/04 {null}
    5 EMAIL 2003/12/04 {null}
    6 DADO DE BAJA 2003/12/18 {null}


    The result should be something like this:

    CDACCION DSACCION FEALTA FEBAJA
    ======== ============ ==========
    1 IMPRIMIR 2003/12/04 {null}
    2 ENVIAR 2003/12/04 {null}
    3 LLAMADA 2003/12/04 {null}
    9 NUEVO 2004/02/16 {null}
    4 RECIBIR 2003/12/04 {null}
    5 EMAIL 2003/12/04 {null}
    6 DADO DE BAJA 2003/12/18 {null}
    7 ASDASDASD 2004/02/16 2004/02/16
    8 ASDASDADS 2004/02/16 2004/02/16
    10 2382 2004/02/16 2004/02/16

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Order By

    Your DECODE doesn't work. It attempts to order by one or other of the following constant text strings: 'FEBAJA DESC,DSACCION ASC', 'DSACCION DESC', not by column values.

    Try something more like:

    ORDER BY febaja DESC NULLS FIRST, dsaccion

    Or if you want DSACCION to be ASCENDING when FEBAJA is NULL and DESCENDING when FEBAJA is NOT NULL then:

    ORDER BY febaja DESC NULLS FIRST,
    DECODE(febaja, NULL, dsaccion) ASC,
    DECODE(febaja, NULL, NULL, dsaccion) DESC

  3. #3
    Join Date
    Jun 2003
    Posts
    294

    Re: Order By

    Thanks man, that's the answer !!!!!!!!!!!!

    It works ok now

Posting Permissions

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