Dense_Rank() over order by date fields not working properly

Hi,
i have a pl/sql statement which looks like this:
WITH OrderedByDateTable     AS
     SELECT     gsp.*, DENSE_RANK () OVER (ORDER BY A_varChar_col1,
decode(upper('COMPLIANCETICKSDATE'),'TASKNBR',TASK_NBR,
'DESCRIPTION', DESCRIPTION,
'PARTNBR', PART_NBR,
'PARTSERIALNBR', PART_SERIAL_NBR,
'SORTDATE', TO_DATE(MIN_EST_DUE_DATE),
'COMPLIANCETICKSDATE', COMPLIANCE_DATE,
TASK_NBR
)DESC NULLS LAST,task_nbr,description,enrtask_id)     AS r_num
     FROM     GT_STATUS_PAGING gsp
SELECT     *
FROM     OrderedByDateTable     
The result that i am expecting is that the dense_rank should order the compliance_date column in desc order and finally gives ranks to the rows.
But i am getting the resultset in some order all the time, but it is neither ASC or DESC.
But if for debugging purposes, lets say if i replace the COMPLIANCE_DATE column with DESCRIPTION column again it works perfectly fine giving me the descriptions in DESC order along with the ranks. But for both the date fields above it doesnt work.
Can anyone please help me on how to solve this?

user12270778 wrote:
Hi,
i have a pl/sql statement which looks like this:
The result that i am expecting is that the dense_rank should order the compliance_date column in desc order and finally gives ranks to the rows.
But i am getting the resultset in some order all the time, but it is neither ASC or DESC.
Can anyone please help me on how to solve this?The problem is an implicit date conversion that takes place.
Because the first parameters of your decode are strings, the COMPLIANCE_DATE column is also converted into a string. This string is then sorted alphanumerically. The default format mask is often DD-MON-RR. Therefore your date column would be sorted by day, then by the name of the month and so on.
Fast solution would be to do an explicit conversion from date into strings that match the ordering.
WITH  OrderedByDateTable     AS
        (     SELECT     gsp.*, DENSE_RANK () OVER (ORDER BY  A_varChar_col1,
                     decode(upper('COMPLIANCETICKSDATE'),
                               'TASKNBR',TASK_NBR,
                               'DESCRIPTION', DESCRIPTION,
                               'PARTNBR', PART_NBR,
                               'PARTSERIALNBR', PART_SERIAL_NBR,
                               'SORTDATE', TO_DATE(MIN_EST_DUE_DATE),
                               'COMPLIANCETICKSDATE', to_char(COMPLIANCE_DATE,'YYYYMMDD HH24:MI:SS'), /* this is the important bit */
                               TASK_NBR
                               ) DESC NULLS LAST,task_nbr,description,enrtask_id)     AS r_num
                    FROM     GT_STATUS_PAGING  gsp
SELECT     *
FROM     OrderedByDateTable     You should be careful, because the same problem also happens with your SORTDATE column MIN_EST_DUE_DATE.
Edited by: Sven W. on Oct 25, 2012 6:53 PM

Similar Messages

  • Help for date field not working after upgrade

    hi experts,
    In our BSP application for a page we had an inputfield (date).
    Onvaluehelp for input field we were calling the saphelpdate function.
    however after upgrade this functionality is not working properly as no pop up comes after clicking on the icon.
    we have upgraded to SPS 16 recently.
    please help me.
    regards,
    Arvind.

    Hi, I try upper case but nothing happen. This is all my code by far, I hope you can help me:
    DATA: BEGIN OF T_PCONT OCCURS 0,
          PCONT LIKE ZPSPERMISOS-PSOBKEY,
    END OF T_PCONT.
    DATA: BEGIN OF T_FIELDS OCCURS 0.
            INCLUDE STRUCTURE help_value.
    DATA END OF T_FIELDS.
    DATA: BEGIN OF T_VALUES OCCURS 0,
          VALUE(60) TYPE c.
    DATA: END OF T_VALUES.
    DATA: N TYPE i.
    SELECTION-SCREEN BEGIN OF BLOCK  b20 WITH FRAME TITLE text-b02.
      SELECT-OPTIONS:
        P_CONT FOR  ZPSPERMISOSH-PSOBKEY OBLIGATORY NO-EXTENSION NO INTERVALS,
        P_INT  FOR  ZPSPERMISOSH-PARTNER OBLIGATORY NO-EXTENSION NO INTERVALS,
        P_FEC  FOR  ZPSPERMISOSH-ZFINICN NO-EXTENSION NO INTERVALS,    
        P_RAZ  FOR  ZPSPERMISOSH-ZRAZONFINIC NO-EXTENSION NO INTERVALS.
    SELECTION-SCREEN END OF BLOCK b20.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_CONT-LOW.
      PERFORM P_HELP_P_CONT USING P_CONT-LOW.
    *&      Form  P_HELP_P_CONT
    FORM P_HELP_P_CONT  USING P_P_CONT.
      DESCRIBE TABLE T_PCONT LINES N.
      IF N EQ 0.
        T_FIELDS-FIELDNAME  = 'PSOBKEY'.
        T_FIELDS-TABNAME    = 'ZPSPERMISOS'.
        T_FIELDS-SELECTFLAG = 'X'.
        APPEND T_FIELDS.
        CLEAR T_FIELDS.
        SELECT PSOBKEY FROM ZPSPERMISOS
        INTO  TABLE T_PCONT.
        SORT T_PCONT BY PCONT.
      CALL FUNCTION 'HELP_VALUES_GET_WITH_TABLE'
        EXPORTING
          CUCOL        = 10
          CUROW        = 1
          TABNAME      = 'T_PCONT'
          FIELDNAME    = 'PCONT'
        IMPORTING
          SELECT_VALUE = P_P_CONT
        TABLES
          FIELDS       = T_FIELDS
          VALUETAB     = T_VALUES.
    ENDFORM.                    " P_HELP_P_CONT
    Edited by: J. Garibaldi on Nov 25, 2009 11:14 AM
    Edited by: J. Garibaldi on Nov 25, 2009 11:16 AM

  • Date field not working like a date field

    We have quite a few date objects in the Universe but only some seem to function as a date field whereas some do not.
    The easiest way to tell whether a date field is functioning as a date field seems to be to add the date fields as a filter in a query. If it is a proper date field a Calendar option appears. If it is not, no Calendar option appears.
    In the screenshot below, the Latest Approved Date functions like a proper date object and shows a calendar option. The other field does not even though it is a date field too.
    I'm checking with this forum as the Universe designer didn't have any answer for this.

    HI Vivek,
    Go to Universe Designer
    click on object (Latest Approved Date)
    click on definition
    go to TYPE scroll down and select type as DATE
    and export now check the filter it will work
    try once
    Regards,
    Ranjeet

  • IDoc string field to JDBC date field - Not working

    Hello everyone,
    Once again I must ask you something that is keeping me..
    I had a interface type RFC ASync to JDBC SQL Server, it was working fine. Then, I was asked to change to a type iDoc ASync to JDBC SQL Server.
    At first, it was not a problem, just manual work. But them, I am getting an error.
    In the RFC, I had a date field, that was directly related to the date field on the JDBC destination, so the mapping was pretty much straight forward. The SQL INSERT command was working fine on this cenario.
    Now, in iDoc, this field was automatically converted to a string, and somehow, PI is not understanding that string has to be mapped to a date field in the JDBC.
    Is there any 'workaround' for me to do this?
    Thanks!
    Ricardo Sancio Lóra
    Brazil

    The issue here is that somehow, the same SQL insert command that was working, does not work anymore.
    This is the SQL command took from RWB log monitor:
    INSERT INTO  aniversariantes_sap (matricula, nome, nascimento, unidade) VALUES (00000070, 'Ricardo Lora', '19851216', 00000000)
    If I run this query on my DB it works.
    But, in PI, it's not, here is the error:
    Could not execute statement for table/stored proc. "aniversariantes_sap" (structure "ANIVERSARIANTES_SAP") due to com.microsoft.sqlserver.jdbc.SQLServerException: Syntax error converting datetime from character string.
    I´ve tried cast() and convert() using mapping 'habilities', but also, does not work. Work if I run in the DB, but not if PI runs it.
    Wierd..
    Ricardo

  • Select-a-date field not working on iPhone

    I'm having trouble getting this form to work on a mobile device: www.centralparkpetretreat.com/contact-us
    There are 2 select-a-date fields on this form (drop-off date and pick-up date). The first one works and the second one doesn't. It seems to only be a problem on an iPhone. Has anyone else encountered this problem? Any ideas?
    Thanks!

    HI Vivek,
    Go to Universe Designer
    click on object (Latest Approved Date)
    click on definition
    go to TYPE scroll down and select type as DATE
    and export now check the filter it will work
    try once
    Regards,
    Ranjeet

  • Date field not working in Query definition

    Hello Experts ,
    I am trying to prepare one report which will pull some fields ( extended fields ) from Rfx header page and display in the report . For this I have made one  query definition and written SQL query .  Now all fields except the date fields are successfully fetched and displayed by the query .  Only when I am adding the date field inside "result field" tab , the query is throwing error  like -
    " ORA-00904: "EFFECTIVE_START_DATE": invalid identifier   "
    but this field name is correct  .
    Any formatting needs for this field ?
    Regards
    Sudipta

    Hi Sudipta,
    Thanks for your reply.
    Actually I have created a diferent extension field and want to add that field in Results fields of particular Query Definition. But when I use it Tablename.Extension_Field_Name, its giving below exception
    ORA-00904: "t"."fieldname": invalid identifier
    Any idea what needs to be taken care of while using extension fields in Queries.
    Thanks,
    Saloni

  • Oracle date field not comparing properly with to_date function

    Hi, i'm facing a very weird problem. I'm triyng to retrieve a range of records in between two dates. However, it doesn't seem to understand. What am i doing wrong?
    let's say my table (MYRECORD) has this (where id is varchar and date is DATE and not timestamp) :
    ID DATE
    1 22-JAN-08
    2 22-JAN-08
    3 21-JAN-10
    4 11-FEB-10
    5 11-FEB-10
    So, let's say iwanna get the records from 21st Jan 2010 :
    select
    date as ori_date from MYRECORD where
    date = to_date('21/01/2010','DD/MM/YYYY')
    1.)
    it is not returning any record at all. I'm having problems with between dates and the to_date function as well,
    so i'm trying to get the 'equal' part working first. I can't use to_char because at the end of the day,
    i need to compare between dates.
    what am i doing wrong? has this got anything to do with what kind of format is set up on the oracle server?
    running :
    SELECT value FROM v$nls_parameters WHERE parameter ='NLS_DATE_FORMAT'
    returns DD-MON-RR
    2.) how do we compare dates from the table according to our own specified format from our passed string? I only have READONLY access to this database
    so i can't set anything up.

    please run this
    select To_date(date, 'DD/MM/YYYY HH24:MI:SS') as ori_date from MYRECORDprobably you have hour minute second info in your table, to_date('01012010','DDMMYYYY') means hour, minute and second is 00:00:00 so it wont be equal.The database field type is actually 'DATE' and not datetime. I've also ran the sql you provided to show its timestamp, but it's not showing anything as far as timestamp is concerned. It's showing only the date. So does this mean it's a real date only information?
    However, it might be more efficient to do two comparisons, especially if there's an index on dt:
    WHERE   dt >= TO_DATE ('21/01/2010', 'DD/MM/YYYY')
    AND     dt <  TO_DATE ('22/01/2010', 'DD/MM/YYYY')
    Ok. If we change the range to compare it on the same day, it won't work;
    WHERE   dt >= TO_DATE ('21/01/2010', 'DD/MM/YYYY')
    AND     dt <=  TO_DATE ('21/01/2010', 'DD/MM/YYYY')this also happens if we're using BETWEEN
    this is real weird. It's supposed to work...i don't recall having this kind of issue on other databases. If that's the case,
    each time a user passes me a date string i have to somehow add another day onto its 'to' comparison date in order for things to work.
    but..i don't want to since i don't want to accidentally include the extra day's results!
    Edited by: 803998 on Oct 21, 2010 8:14 PM
    Edited by: 803998 on Oct 21, 2010 8:33 PM

  • Table date filter not working properly

    Hi OTN,
    I have noticed that table date filter not always working properly.
    When I copy actual value from column outputText to column filter and hit Enter - I see an empty table.
    http://imageshack.us/photo/my-images/818/filter.png/
    I suspect the problem to lie among date formats.
    But I tried to delete convertDateTime from outputText or add it under filter inputDate. Nothing helped.
    <af:column sortProperty="Hisdate" sortable="true"
                                     headerText="#{bindings.InformationView1.hints.Hisdate.label}"
                                     id="c8" visible="false" filterable="true"
                                     width="83">
                            <af:outputText value="#{row.Hisdate}" id="ot5">
                              <af:convertDateTime pattern="#{bindings.InformationView1.hints.Hisdate.format}"/> // or without both lines
                            </af:outputText>
                            <f:facet name="filter">
                              <af:inputDate id="id15"
                                            value="#{vs.filterCriteria.Hisdate}"
                                            columns="8">
                                <af:convertDateTime pattern="#{bindings.InformationView1.hints.Hisdate.format}"/> // or without both lines
                              </af:inputDate>
                            </f:facet>
                          </af:column>Nothing special about the attribute. A database table field of type DATE. In database this (see picture) row has exactly "06.06.2006".
    Could you please point me out where to start seeking?
    Thanks.
    JDev 11.1.1.4

    Well, OK. I think I'd better have 2 attributes: truncated date for filter and full date with time for edit.
    What is an attribute type for datetime?
    select trunc(t.HISDATE) AS HISDATE -- date attribute type
        ,to_char(t.HISDATE, 'dd.mm.yyyy hh24:mi') AS HISDATETIME -- timestamp/date attribute type?Something like this?

  • Property for fields not working properly.

    Hi
    I am doing some validation on tab strip.
    initially on some value my tab strip is coming,due to visibility binding property.
    now i am trying to do visibility binding on individual tabs of tab strip on user based,which is not working.
    is there any way to make it work out.
    my code:     
       call method wd_context->set_attribute
            EXPORTING
              name  = `PROP_CREDIT`    "Context attr name
              value = space.
    to hide a credit view, i had attached a attr to its transparent cont.,& have passed the value space to make it non visible.
    but it not working,i am doing this like enabled,visible on 3-4 tables,but noting happening.
    pls let me know how to make it work.

    HI Vipin,
    I have tested ouy this way...
    Ihave a TB with 3 tabs, Last tab has got One TC inside which there are 2 other TCs(TC2,3) with Input fields inside them.
    I bound the ENABLED property of TC2 to the ENABLE(wdy_boolean) property and coded in DOINIT of view.
    I didnt code it in modifyview.
    Its working fine for me..
    Please test it in some demo application you will get to know the errors.
    DATA lv_enable TYPE wd_this->element_context-enable.
    * get element via lead selection
      lo_el_context = wd_context->get_element( ).
    * @TODO handle not set lead selection
      IF lo_el_context IS INITIAL.
      ENDIF.
    * @TODO fill attribute
    lv_enable = abap_false.
    * set single attribute
      lo_el_context->set_attribute(
        name =  `ENABLE`
        value = lv_enable ).
    I guess, there is some thing going wrong  in MODIFYVIEW. for every event this gets triggered right.
    Now the TC2 got disabled also the Inoutfield inside it got disabled.
    Regards,
    Lekha.
    Edited by: Lekha on Oct 16, 2009 4:08 PM

  • Foreign Exchange - Posting date - updation - Not Working Properly

    Hi Friends,
    At the time of posting the Purchase invoice in Transaction Code MIRO, the system is picking the Exchange rates form the table based on our posting date in the Invoice screen.
    System is not updating the exchange rate, if we change the Posting date just before posting.
    Example:
    Transaction code MIRO
    Posting date 21.01.2010; Exchange rate picked by system - 46.67 (USD and INR) Maintained in Table - 21.01.2010 - Rs.46.67
    before posting we are changing the posting date from 21.01.2010 to 22.01.2010
    Posting date 22.01.2010; Exchange rate picked by system - 46.67 (USD and INR) maintained in Tabl - 22.01.2010 - Rs.46.99
    To bring the correct exchange rate into effect, We are coming out of the Transaction code and Re-entering the correct posting date.
    Is there is any solution to make the system pick the exchage rate whenever we change the posting date?
    Thanks in advance friends and collegues

    Thanks for Quick reply
    I have a separte Exchange rate in PO (purchase Order) and I have not activated the fixed Exchage rate in the Purchase Order
    If I have activated the Fixed Exchange rate in Purchase order - then the system will not accept other Exchange rates in Transaction Code MIRO (booking LIV)
    I have not activated the Fixed Exchange rate in Purchase order (Please have a look at the Purchase Order - A check box for maintaining the Fixed Exchange rate through out the P2P Cycle.
    If the fixed exchange rate is notactivated in PO, the system will pick the Posting Date in the Transaction Code MIRO (LIV) for calculating the Exchange rate.
    Now my query is why the system is not changing the Exchange rate automatically when I change the Posting date in Transaction Code MIRO. Please also let me know what should be done from our side so that whenever I change the posting date in Transaction Code MIRO, the system should pick the Exchange Rate according to the Posting Date in Transaction Code MIRO.
    Thanks for showing Interest
    Thak you and Kindest Rgeards
    Srikaanth

  • 0GL_ACCOUNT Hirearchy Data Source not working properly

    Hi All,
        I am trying to upload hierarchies for 0GL_ACCOUNT using data source 0GL_ACCOUNT_T011_HIER. But its getting failed. In R3 the data source is working fine. When I m displaying data source in RSA1 it displays Version : Modified , Active Version : Does not exist. Is this normal?
    I am using transfer method IDOC. what may be the reasons behind the failure?
    Regards:
    Jitendra

    Hi  Jitendra,
    Did  you already try to activate DS again?  Please try it with rpeort RS_TRANSTRU_ACTIVATE_ALL, using  for 0GL_ACCOUNT _HIER and name of source system  as parameters.
    Hope this helps
    Joe.

  • Sort Fields Not Working Properly?

    If I do Get Info on a track, and change the Sort Artist to anything, then I Right Click on the track in the library > Apply Sort Field > Same Artist it changes the Sort Artist of all tracks by that artist to what I entered.
    However, I want to delete all the Sort Artist data. I do exactly the same thing, and change the Sort Artist data to nothing on a track. However when I try to apply the sort field to all tracks by the artist it leaves them alone! It doesn't change all the Sort Artists to nothing! It only does this when I enter no data. Any string at all and it works correctly.
    How can I change all the Sort Artists to nothing i.e. delete the Sort Artist data?

    Hi there.
    How about, instead of leaving the Sort Artist field blank, entering a name that is identical to the actual Artist field instead and then use the Apply Sort Field > Same Artist option.
    You can then go to the iTunes View menu > View Options command and uncheck Sort Artist so that it will no longer appear in your iTunes Library display.
    Does that bring you anything in the way of satisfaction?

  • Date Function not working properly

    Dear Gurus,
    I have a plan app and the pertinent essbase cube, I need to retrieve the no. of days for the curr month/year combination.
    On version 11.1.1.3 I used something like : @TODATE("dd-mm-yyyy",@CONCATENATE("01-01-",@NAME(@ALIAS(@CURRMBR("year"))))) / 86400;
    and it worked fine.
    When I moved the formula on the 11.1.2 version I get an error " invalid argument in function @_TODATE".
    I know that essbase was never really good with dates.
    Any help I appreciate.
    yannis

    Hi Yannis,
    1. I see no reason for it not to work on 11.1.2, when it had run flawlessly on 11.1.1.3.
    2. Looking at the tech reference of @TODATE, nothing seems to have changed , there is only one difference.which is the latest data supported by the function in 11.1.2 is 12-31-2037,while its 01-01-2038 in version 11.1.1.3.
    3. Sounds silly, but try to validate the formula which was resulting in errors in 11.1.2 , on 11.1.1.3 once.
    Sandeep Reddy Enti
    HCC
    http://hyperionconsultancy.com/

  • Date arithmatics not working properly

    if i m passing a varchar string and this string is in a default date format then
    it should be converted to dd-mon-rr
    SQL> select '12-jan-04'+3 from dual;
    select '12-jan-04'+3 from dual
    ERROR at line 1:
    ORA-01722: invalid number
    but instead of that if i m using to_date then its working...
    1* select to_Date('26-feb-04')+5 from dual
    SQL> /
    TO_DATE('
    02-MAR-04

    In the first statement, Oracle has no idea that the string happens to be convertable to a date using the session's NLS_DATE_FORMAT setting. Oracle doesn't try that conversion unless you do an explicit conversion.
    Justin

  • Mobile data key Not working properly

    I have owned both c3 and e4. In both maximum 3 to 4 only it is working. Afterthat I need to be restart my device. I think this will be solved in next updates.

     Which key are you referring to ? 

Maybe you are looking for

  • Using NetBeans and Eclipse to drag and drop forms, controls etc

    Hi, can you use NetBeans and Eclipse to drag and drop like say with C# in MS Visual Studio ? like forms and listboxes, textboxes etc ??

  • In what cases does Apple usually choose to just replace an iPhone instead of repairing it?

    From your guys' experiences, what qualifies for a free iPhone replacement by Apple? I'm taking my iPhone 4 in tomorrow for a stuck sleep/wake button. I've tried blowing any debris out of the button's surrounding area and even shook the phone upside d

  • HR-ABAP catsdb and pa0001 link

    Hi all, I am using  catsdb and Pa0001 tables.In my selection screen i am using workdate field. In My report i have to display only exempt employees depending on workdate ranges only. I want to know how to link between these two tables using exmpt emp

  • CUCM full configuration in text format

    Dear All, Can we pull out the CUCM full configuration in text format ? Actually one of My customer wants CUCM' confiuration in text format to check feasibility to add CUCM to "Device Expert" like switches, router etc. Below is the overview of Device

  • Syncing contacts creates duplicates

    I would be grateful for any help. I don't sync my iPhone 3GS as often as I would like because when I do, I end up with all my contacts being duplicated. What I want is for all new/edited/deleted entries on my PC to be appropriately adjusted on my iPh