Sort the table values in asc or desc

I have a table named date_table contains two columns (Term,multiplier) with values given below
Term Multiplier
1 M
2 M
8 Y
15 D
2 Y
24 M
1800 D
Values given above are term and multipiler.Means 1 M stands 1 month,15 D stands for 15 Days 2 Y stands for 2years. I need a query to select this values in asc or desc order as given below
Term Multiplier
15 D
1 M
2 M
24 M
2 Y
1800 D
8 Y

As others have mentioned, there isn't a fixed number of days in a month or a year so it would be incorrect to assume 28, 30 or 31 days in a month or that there are 365 days in a year (as leap years have 366).
The truest way to determine it is to calculate it using proper date functionality around a base date e.g. you could calculate it from todays date...
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 1 as term, 'M' as multiplier from dual union all
  2             select 2, 'M' from dual union all
  3             select 8, 'Y' from dual union all
  4             select 15, 'D' from dual union all
  5             select 2, 'Y' from dual union all
  6             select 24, 'M' from dual union all
  7             select 1800, 'D' from dual)
  8  --
  9  select term, multiplier
10  from t
11  order by case multiplier when 'D' then sysdate+term
12                           when 'M' then add_months(sysdate,term)
13                           else add_months(sysdate,12*term)
14*          end
SQL> /
      TERM M
        15 D
         1 M
         2 M
         2 Y
        24 M
      1800 D
         8 Y
7 rows selected.
SQL>This way, oracle will accurately work out the date offsets taking into account the number of days in each month and leap years.

Similar Messages

  • 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

  • How to sort  the arry value in ascending order

    I have a string array where i need to sort the below values in ascending order in the same format...can anyone give me clue on this?
    9.3
    3.1
    9.1
    19.1
    19
    9.4
    9.1.1
    the sorted order should be
    3.1
    9.1
    9.1.1
    9.3
    9.4
    19
    19.1

    You may have easier luck writing your own comparator for this. These are headings in a table of contents, right?
    Write a comparator that tokenizes a string on the '.' character, or use a StringBuffer to remove them, and then order the elements according to the combined numbers. Since alphanumeric would order this list as you want it anyway you could just order that way once the '.' are removed.
    In other words your comparator would do this in the "compare" method:
    public class MyComparator implements Comparator, java.io.Serializable {
    private static Comparator stringComparator = java.text.Collator.getInstance();
    ...constructor(s), your own private "instance" variable of type MyComparator, a getInstance() method of your own, yadda yadda...
    public int compare(Object item1, Object item2) {
    try {
    value1 = removePeriods((String)item1);
    value2 = removePeriods((String)item2);
    if (value1 == null) {
    return (value2 == null) ? 0 : (-1);
    return compare(value1, value2);
    } catch (ClassCastException cce) {
    System.err.println("Wrong Object Type, JackAss!");
    protected int compare(String str1, String str2) {
    return MyComparator.stringComparator.compare(str1, str2);
    private String removePeriods(String value) {
    StringBuffer sb = new StringBuffer(value);
    int decimalIndex = value.indexOf('.');
    while (decimalIndex != -1) {
    sb.delete(decimalIndex, (decimalIndex + 1));
    }

  • Problem sorting the table .

    hi
    iam trying to sort the table in ascending
    and descending order ,
    but  iam not able to sort my model node  table .
    below is the code i have written
    and other thing i have created a class called Tablesorter.java
    and  copied the code of the TableSorter present in
      IDE\eclipse\examples   as  i was not able to copy and
    paste the TableSorter Class  ,  in the 
      src\pkg.
    import com.sap.tc.webdynpro.tests.utils.TableSorter;
    if(firstTime)
               view.nowCreateAllCustomExtensionFields();
          IWDTable tab= (IWDTable)view.getElement("Table");
          wdContext.currentContextElement().setCustomerTableSorter(new TableSorter(tab,wdThis.wdGetTableSortAction(),null,new String[] {"Customers") ));     
    in the above coding i am getting error as  Constructor TableSorter  is undefined.
    wdContext.currentContextElement().getCustomerTableSorter().sort(wdEvent,wdContext.nodeCustomers());
    can any one help me out ?

    hi
    thanks for the response 
        i cannot copy the model node data to the value node 
       as  i am performing some operations in the itemlistbox
      and then populating the model node  table  
    and there will be  thousands of  data  , so copying
    the data to the value node will affect the performance
      and other thing is i have one more table of model node
    where i have to perform sorting  , so is there a way
    that TABLESORTING  can be directly performed on the
    model node ,  i have to perform ascending and descending order  sorting on the two tables w.r.t the columns 
    can any one help me out ?

  • How to update the table value in the valuechange event?

    I have an input field in the datatable with the valueChangeListener
    <rich:dataTable id="cart" value="#{cart.cartList}" var="item">
    <h:inputText value="#{item.cost}" id="qty" valueChangeListener="#{items.updateCost}" onchange="submit()">
    <h:outputText value="#{item.errorMsg}"> </h:outputText>
    in the backing bean
         Item item = (Item) model.getRowData();
    // do some update, if the cost too larger, change to max_cost
         item.setCost(max_cost);
         item.setErrorMsg("Error Msg");
    After calling the valuechange method, the screen output doesn't update the cost.
    How to update the table value in the valuechange event?

    As you're misusing the valueChangeListener to set another input field, you need to skip the update model values phase. Otherwise the value set in the valueChangeListener will be overridden by the submitted value. You can do this by calling the FacesContext#renderResponse() inside the valueChangeListener method. This will shift the current phase immediately to the render response phase, hereby skipping the update model values and invoke application phases.

  • How to print the table values in fastest way?

    Dear Friends,
    I'm having table in my application and i need to print the table values. For that I used print() method to print the table values.
    boolean complete = tableObj.print(mode, header, footer, showPrintDialog, null, interactive,
                                  null);But, the time taken for displaying print dialouge box so late and printing operation is done very slowly.
    Could anyone please tell me is there any better way and fastest way to print the table values?
    Thanks in advance

    Hi,
    In the Module pool you will have fields. For those fields you have created the name also. Assign those name to work area and from there to internal table.
    And for your requirement viceversa you need to done.
    With Regards,
    Sumodh.P

  • Sorting the table

    Dear Guru's
      Can you please advice me how I can sort the table data in Adobe Interactive form.
    Thanks!
    Surya.

    Hi,
    In the context area , Double click on the table.
    In the bottom area u can see the properties tab....
    In that go to control levels tab where u cna set the sorting on the basis of a particular field.
    Please let me know if you find any issue.
    Regards,
    sasi

  • Sorting the level value in dimension

    After mapping the dimension table to a dimension, the level value is not in order when quering the data in OWB. How can I sort the data in dimension to a specific order ie, year and month?
    Thanks for your help
    Edwin

    Hi Edwin
    Do you mean using the dimensional data viewers? No sort metadata information is captured on the dimension itself in OWB (but is for the business defs if deploying to Discoverer), so you will have to do this in the query tool or in AWM (if AW). Which implementation (AW/ROLAP) are you using and what is your planned report tool?
    Cheers
    David

  • Sorting the table records based on date (stored as string in the database)

    Iam storing the date as string(varchar2) in the database.
    Date format: DD-MMM-YYYY hh:mm:ss am/pm
    example: 12-MAY-1984 11:12:45 AM
    now i have to sort the records in such a way that recent records should be displayed first, then past records.
    i need help reagrding

    Step one: Select from the table
    Step two: Convert the string to a date
    Step three. Order on this converted date descending (= recenct records first)

  • How to sort the characteristic values in layout

    Hello,
    I wont to use a layout with key figs in data columns and two characteristics in lead columns. The problem is that the sorting of first characteristic values is displayed in alphabetical order. How can I change the order to another exact defined combinations for characteristic values?
    I read the thread with the same problem (see below the link), but the solutions are not satisfacroty.
    Has anyone another idee?
    Thanks for any help!
    Larissa Bräutigam

    Hi Larissa;
    I had the same problem and they propose this:
    Attributesu0092 order that the system displays in the Planning Layout
    That was not the solution presented to the customer. Because of system performance, a programmer was there and created a VBA code. But I wasn't there so I don't have the code.
    regards

  • Chaging the table value after update

    Hi All,
    I want to update a certain column ( date column ) after update is done. I can do this using "before update" trigger. But I'm getting some transaction issues when the trigger is written as before update ( Error from java side saying data is modified outside the transaction ) . So i was wondering whether there's another way to achieve the same, whether I can change data after update is done. I searched the net and found "cannot change NEW values for this after update trigger type". Anyone knows how to do this ?
    Thanks in Advance !

    Hi all,
    I found the real reason for this problem. Entity bean for table which I'm trying to write trigger, has concurrency-strategy="Optimistic" and optimistic-column="db_mod_date". This db_mod_date is the column which I was trying to update using a trigger.
    i.e Following configuration set to entity bean. Therefore weblogic updating "db_mod_date", hence no need of trigger.
    @weblogic.cache concurrency-strategy="Optimistic" max-beans-in-cache="200" idle-timeout-seconds="60" cache-between-transactions="true"
    @weblogic.persistence delay-updates-until-end-of-tx="True" verify-columns="Timestamp" optimistic-column="db_mod_date"
    More Details
    [http://docs.oracle.com/cd/E11035_01/wls100/perform/EJBTuning.html|http://docs.oracle.com/cd/E11035_01/wls100/perform/EJBTuning.html]
    Thanks !

  • Call an executable program inside function module and pass the table values

    Hi,
           i'm pretty new to HR Abap programming. I have a requirement like "calling an executable program within a function module and the output of the program data(Stored in internal tables) should be passed to the function module tables".
    I've some idea about SUBMIT keyword and i used it in the function module..
    Please do the needful to solve this.
    Regards,
    Selvi.

    Hi,
    Thanks for all your reply.
      I've used Option 3 as per dsouzajovito suggestion. Now i'm getting data in function module tables using import/ export table to memory concept.
    Again a small issue arises, while i'm executing function module it fetches all pernr available in the server and displays the details of last pernr. GET pernr statement is used in the Z report and submit statement is used like this as follows.
      SUBMIT ZHR_RFC_PAYSLIP   WITH  PERNR-PERNR EQ EMPCODE
                                          WITH PYBEGDA EQ FDATE
                                          WITH PYENDDA EQ LDATE
                                          AND RETURN.
    Pls suggest if there is any corrections in the code.
    If i give a pernr as input in the function module, then it should fetch the details related only to that pernr.
    FYI, No selection screen is used here as per requirement.
    Regards,
    Selvi.

  • How get the all the table values to another table based on Action

    Hi All,
    I am new to webdyn pro.
    I have two tables Table1 and Table2 with context nodes Tab and Tab1.
    Table1 I have a button Save If I submit Save the data from first table to second table .
    I was written the code
    IPrivateTableScrollBar.ITabElement element;
         for(int i=0;i<10;i++)
              element=wdContext.createTabElement();
              element.setName("test"+i);
              element.setSal("100"+i);
              wdContext.nodeTab().addElement(element);
    added some data to first table.
    how can I get the all 10 rows from first table to second table  if I write wdContext.node<Element>.getName() and getSal() I can get only selected one row .how can I get the all rows in a sigle click to second table.
    please help.

    Hi mohammed,
    Use the following lines of code to iterate through the elements :
    Iprivate<your view>.I<your node1 name>Element elmt1 = null;
    Iprivate<your view>.I<your node2 name>Element elmt2 = null;
    for(int i=0;i<wdContext.node<your node1 name>().size();i++)
    elmt2 = wdContext.node<your node2 name>().create<your node2 name>Element();
    elmt1 = wdContext.node<your node1 name>().get<your node1 name>ElementAt(i);
    elmt2.set<attribute name>(elmt1.get<attribute name>);
    wdContext.node<your node2 name>().addElement(elmt2);
    Hope this helps,
    Best Regards,
    Nibu.

  • Sort the Valuenode records in table

    Hi Experts,
    Following is the code I wore to retrive and display Portal roles in a table. The context maintained is as follows and got the results properly. I want to know how to sort the table values by Role_Name?. Could some one help me?
    [Value node]      Role_table
    [Value Attribute] RoleID
    [Value Attribute] Role_Name
    [Value Attribute] PCD_Location
    //Retrive the roles from the Role factory          
    String[] theroles = rolefact.getRolesOfUser(unique_id,true);
    for(int i=0; i<theroles.length; i++ )
    //Retrive user attributes and add to the context attribute values     
    String roleid = rolefact.getRole(theroles<i>).getDisplayName();          
    String rolename = rolefact.getRole(theroles<i>).getDescription();
    String role_desc = rolefact.getRole(theroles<i>).getUniqueName();
    IPrivateUserView.IRole_tableElement rowelement = wdContext.createRole_tableElement();
    rowelement.setAttributeValue("RoleID",roleid);
    rowelement.setAttributeValue("Role_Name",rolename);
    rowelement.setAttributeValue("PCD_Location",role_desc);
    //Append the roles obtained and bind to the rolenode
    al.add(rowelement);
    wdContext.nodeRole_table().bind(al);
    Please help me with some code on how to sort the value node table?. I promise to award the points for the right solution. I appreciate coding help.
    Thank you
    Regards
    Maruti

    Hi Maruti,
    1. Get the size of the node, save it in a variable say <b>si</b>
    int si = wdContext.nodeRole_table().size();
    2. Iterate as follows
    for(int i=0;i<si;i++)   
         for(int j=i+1;j<si;j++)
             if(wdContext.nodeRole_table().getRole_tableElementAt(i).getAttributeAsText("Role_Name").compareToIgnoreCase(wdContext.nodeRole_table().getRole_tableElementAt(j).getAttributeAsText("Role_Name"))<0)
             wdContext.nodeRole_table().swapElements(i,j);
    Regards,
    Mathan MP

  • Sorting the content of table at first showing of the table

    Hi WD Experts,
    I can't find the solution of this very important case
    Suppose this very simple scenario:
    I have master-detail relation between two tables
    and I try to show the content of detail table in some order (ascending order of first column)
    Also in UI I want to see the sorting icon
    I do this with generating of CustomEvent in OnLeadSelect
          HashMap map = new HashMap();
          map.put("col", "Version");     
          IWDCustomEvent wdEvent = new CustomEvent("onActionSort", map, true);
          wdThis.onActionSort(wdEvent);
    but unfortunately my detail table is ordered alternately
    (asc and desc order)
    In WD tutorials I find the tutorial for sorting the table
    but sorting is triggered by user action - I want sorting to be executed programmatically and to be executed always in asc order

    Hi Stefan,
    I am using a supply function - and sorting there is workaround - but the user can not see the sorting icon on the proper column - the first appear of icon is when user click on the column header for first time.
    I want user to see which column is sorted initially
    Message was edited by: Rosen Chaushev

Maybe you are looking for

  • Change payroll area in middle of the month

    Currently I had face a problem where this staff whose is reentering the company in the middle of the month. Before this he use payroll area XX, after he reenter the company in the middle of the month, the payroll area need to be change to AA. But the

  • Need help with Berkeley XML DB Performance

    We need help with maximizing performance of our use of Berkeley XML DB. I am filling most of the 29 part question as listed by Oracle's BDB team. Berkeley DB XML Performance Questionnaire 1. Describe the Performance area that you are measuring? What

  • Special Purpose Ledger to refrence original funding source on Goods Issue

    My client has a requirement to purchase stock materials using mutiple funding sources throughout the year (same material, company, plant, valuation area, etc.) We also have a requirement to update the Special Purpose Ledger upon Goods Issue/Stock Tra

  • My laptop has died how do i resync to new computer without losing my ipod data?

    When I connect to my new laptop - it wants to delete all the data on the ipod - is this a limitation of the device or does apple expect our computers to live on forever? - I wish I could retrieve the data off my old laptop but it has died - surely I

  • Request not visible in the version management of a Report Program

    Hi, We Imported an external request into the SAP System. The request was imported successfully and a program already existing is updated with that request, The problem is that the request number is not visible in the Version Management of the Report