Sorting data in a query

Hello Experts,
       In my report I have calender month 'Rate' details based on different entities. Is their a way to sort the Rate in descending or ascending order.
Ex:
            abc company        xyz company
CalMonth   Num  Den   Rate    Num   Den   Rate
jan         2    3     57      5      1    35
feb         3    5     96      3      4    15
mar         8    1     23      7      3    46  
any ideas would be greatly appreciated.
Thanks,
Nikki

Hi Nikki,
I suppose your query looks like this
Comp code1  1.000
            0.941
            0.813
            0.790
Comp code2  0.805
            0.781
            0.762
Comp code3  0.789
            0.776
Comp code4  0.786
            0.777
If ths is true you would be better following Bhanus approach if you want it sorted irrespective of Comp code or try to pay around with the selection of characteristics to which the condition applies..
Hope this helps
Ashish.

Similar Messages

  • Pb retrieving sorted data from Table in SQL.

    Hi,
    I get problem to retrieve data in the right order from table in database SQL.
    See code attached: code.png
    I want to sort data according to ID number And then to retrieve those data and fill out a ring control in the right order "descending" .
    But i got always ID 2 instead of 1. See attached  picture : control.png
    it seems that the select statement (see under) is not woking properly. But it is working well in a query in Access DataBase .  
    //Select statement
       hstmt = DBActivateSQL (hdbc, ("SELECT * FROM %s ORDER BY ID DESCENDING",szTableName));
       if (hstmt<= DB_SUCCESS) {ShowError(); goto Error;}
    Some idea ??
    Lionel.
    Attachments:
    code.PNG ‏39 KB
    control.png ‏32 KB

    Hello Lionel,
    According to the document Robert linked, the prototype of DBActivateSQL() is:
    int statementHandle = DBActivateSQL (int connectionHandle, char SQLStatement[]);
    For the 2nd parameter(SQLStatement), you're sending:
    ("SELECT * FROM %s ORDER BY ID DESCENDING",szTableName)
    Probably your intention is to substitute %s with szTableName, but that's not what it happens.
    By using comma operator, ("SELECT * FROM %s ORDER BY ID DESCENDING",szTableName) is evaluated to szTableName, so you call is equivalent to:
    hstmt = DBActivateSQL (hdbc, szTableName);
    In order to substitute %s with szTableName you need to first build the string you're passing as the 2nd parameter:
    char query[512];
    sprintf(query, "SELECT * FROM %s ORDER BY ID DESCENDING",szTableName);
    hstmt = DBActivateSQL (hdbc, query);

  • Performance - using JDBC call with 'order by' vs sorting data on app server

    Hello! I need some valid thoughts on the performance of using a JDBC call versus processing information on the application server.
    Here is the somewhat simplified scenario:
    I need to retrieve customer information (name, e-mail, telephone), display it in HTML format and then be able to redisplay it in a different order. For example, initially the list would be displayed sorted by last name, but then a user might choose to sort it by e-mail address. Initial call to DB uses 'order by' in the SQL stmt to get me the initial ordering by last name. Results are stored in 2D array. However, when a user selects a different sort I have two options:
    1) just make another call to the DB with a different order by clause. This means I need to create a DB connection, connect to DB, retrieve the results and read them from result set into a 2 dimensional array
    2) re-sort data in the 2D array populated during the initial call. This means I need to use java.util.Arrays.sort(my_2D_resultsArray, my_custom_comparator)
    Question is : which is more efficient? Number of entries retrieved can be anywhere from 0 to a few thousands (depending on other filters such as customer's country). My feeling is that option umber 2 is better, but I would like to get your opinion.
    Thank you!

    Good points! Thanks! I ran a test (see code below) and it takes less than a second to sort 2000 Strings and 2000 nulls. The only thing I ran the test at a UNIX prompt as oppose to from within app server (Weblogic). I expect the speed to be compatible though. Do you think that test was valid and tells us that sorting on the app server is probably faster than doing another SQL query?
    import java.io.*;
    import java.math.*;
    import java.util.*;
    import java.util.Arrays.*;
    public class Test {
      public static void main(String[] args) throws Exception {
        Test test = new Test();
        test.testSortingPerformance();
      public void testSortingPerformance() {
        Object[] objArray2 = new Object[]{};
        Vector v = new Vector();
        Date start, end;
        java.util.Random rd = new java.util.Random(2000);
        for (int i = 0; i < 2000; i++){
          v.add(new Object[]{new String("" + rd.nextInt())});
          v.add(new Object[]{null});
        objArray2 = v.toArray();
        Object[] innerObjArray2 = new Object[]{};
        MyComparator2 myComp = new MyComparator2();
        start = new Date();
        java.util.Arrays.sort(objArray2, myComp);
        end = new Date();
        for (int i = 0; i < objArray2.length; i++) {
          System.out.println();
          innerObjArray2 = (Object[])objArray2;
    for (int j = 0; j < innerObjArray2.length; j++) {
    System.out.print(innerObjArray2[j] + " ");
    System.out.println(v.size());
    System.out.println("Start " + start + " End " + end);
    import java.util.*;
    public class MyComparator2
    implements Comparator {
    //position in the inner array to use for comparison
    private int position = 0;
    //default empty constructor
    public MyComparator2() {
    //implement compare method
    public int compare(Object o1, Object o2) {
    Object[] strAr1 = (Object[]) o1;
    Object[] strAr2 = (Object[]) o2;
    if (strAr1[0] == null){
    if (strAr2[0] == null){
    return 0;
    else{
    return -1;
    else if (strAr2[0] == null){
    return 1;
    return ( (String) strAr1[0]).compareTo( (String) strAr2[0]);

  • How t sort data in chart view (bar chart)

    Hello,
    I have a table view and a chart view in my visual composer model.
    the data in table view are sort A,B, C ---Z
    but in my chart views (bar charts) the listing begins with Z,Y,X,.....A
    (same data service/ BI-Query)
    How can I sort my listing in bar chart so, that the listing begins with A,B,C
    Thanks,
    best regards
    thomas

    Connect the OUT port of dataservice to IN port of SORT operator. This SORT operator is available in Compose > Operators.Configure the SORT operator , select the column on which you want to sort. Then the output of SORT operator should be connected to the IN port of CHART.
    This should give you the desired result.

  • Sort data

    How to sort data query result each time one clicks sort
    button ...sort by name,date,etc

    I did dont work...
    =====
    <CFQUERY NAME="Rec" DATASOURCE="#EazyVector#">
    SELECT ctrData.FACILITY AS Facil,ctrData.CONTRACTNO AS
    CONTRACTNO,ctrData.CONTRACTDATE AS
    CONTRACTDATE,ctrData.CONTRACTTITLE AS
    CONTRACTTITLE,ctrData.DRWPROVIDEBY AS DRWPROVIDEBY,ctrDocs.DRWNO AS
    DRWNO,ctrDocs.SHEETNO AS SHEETNO,ctrDocs.CONTRACTNO AS
    DocCtrNo,ctrDocs.DRWTYPE AS DRWTYPE,ctrDocs.DISCIPLINE AS
    DISCIPLINE,ctrDocs.DRWTITLE AS DRWTITLE,ctrDocs.CONFCADDFILENAME AS
    ImageName,ctrDocs.DRWDATE AS DRWDATE ,ctrDocs.DOCID AS
    DOCID,ctrLoc.READONLYMEDIAPATH AS READONLYMEDIAPATH,
    ctrLoc.CONTRACTNO AS LocCtrNo
    FROM CONTRACTS ctrData,CONTRACT_DOCS
    ctrDocs,IMGS_LOCATION_FOLDER ctrLoc
    WHERE lower(ctrData.CONTRACTNO)=lower(ctrDocs.CONTRACTNO(+))
    AND lower(ctrData.CONTRACTNO)=lower(ctrLoc.CONTRACTNO(+))
    <CFIF Form.ConTNo NEQ "">
    AND lower(ctrData.CONTRACTNO) like lower('%#Form.ConTNo#%')
    </CFIF>
    <CFIF Form.ConTitle NEQ "">
    AND lower(ctrData.CONTRACTTITLE) like
    lower('%#Form.ConTitle#%')
    </CFIF>
    <CFIF #Form.Discipline# NEQ "">
    AND lower(ctrDocs.DISCIPLINE) LIKE
    lower('%#Form.Discipline#%')
    </CFIF>
    <CFIF #Form.DrawingNo# NEQ "">
    AND lower(ctrDocs.DRWNO) LIKE lower('%#Form.DrawingNo#%')
    </CFIF>
    <CFIF #Form.Facil# NEQ "">
    AND lower(ctrData.FACILITY) LIKE lower('%#Form.Facil#%')
    </CFIF>
    <CFIF #Form.DrwTitle# NEQ "">
    AND lower(ctrDocs.DRWTITLE) LIKE lower('%#Form.DrwTitle#%')
    </CFIF>
    <!--- Month
    <CFIF #Form.selectMonth# NEQ "">
    AND EXTRACT(MONTH FROM ctrData.CONTRACTDATE ) IN
    (#ListQualify(Form.selectMonth, "'")#)
    </CFIF>
    <!--- Day --->
    <CFIF #Form.selectDay# NEQ "">
    AND EXTRACT(DAY FROM ctrData.CONTRACTDATE ) IN
    (#ListQualify(Form.selectDay, "'")#)
    </CFIF>
    <!--- Year --->
    <CFIF #Form.selectYear# NEQ "">
    AND EXTRACT(YEAR FROM ctrData.CONTRACTDATE ) IN
    (#ListQualify(Form.selectYear, "'")#)
    </CFIF>--->
    <!--- Between Two Years --->
    <CFIF (#Form.selectYearF# NEQ "") AND (#Form.selectYearT#
    NEQ "")>
    AND ( EXTRACT(YEAR FROM ctrData.CONTRACTDATE ) BETWEEN
    #Form.selectYearF# AND #Form.selectYearT# )
    </CFIF>
    <!--- ORDER by most recent date first --->
    ORDER BY #sortKey# DESC
    </CFQUERY>

  • Sort data results

    How to sort data query result each time one clicks sort
    button ...sort by name,date,etc

    Say for instance you would like to out put the emails,
    fullname and city. Want to sort by each header.
    <cfparam name="sort" default="fullname asc">
    <cfquery name="whatever' datasource="yoursource">
    select *
    from tbl
    order by #sort#
    </cfquery>
    <!---- using U for ascending and D for descending order
    ---->
    <table>
    <tr>
    <td>
    Full Name <a href="page.cfm?sort=fullname
    asc">U</a> | <a href="page.cfm?sort=fullname
    desc">D</a>
    </td>
    <td>
    Email <a href="page.cfm?sort=email asc">U</a> |
    <a href="page.cfm?sort=email desc">D</a>
    </td>
    <td>
    City <a href="page.cfm?sort=city asc">U</a> |
    <a href="page.cfm?sort=city desc">D</a>
    </td>
    </tr>
    <cfquery query="whatever">
    <tr>
    <td>#fullname#
    </td>
    <td>#email#
    </td>
    <td>#city#
    </td>
    </tr>
    </table>
    So when the user clicks on Full Nam U it will send the sort
    value to the query and so forth.
    Hope this helps,
    Sevor Klu

  • Unable to access the data from Data Management Gateway: Query timeout expired

    Hi,
    Since 2-3 days the data refresh is failing on our PowerBI site. I checked below:
    1. The gateway is in running status.
    2. Data source is also in ready status and test connection worked fine too.
    3. Below is the error in System Health -
    Failed to refresh the data source. An internal service error has occurred. Retry the operation at a later time. If the problem persists, contact Microsoft support for further assistance.        
    Error code: 4025
    4. Below is the error in Event Viewer.
    Unable to access the data from Data Management Gateway: Query timeout expired. Please check 1) whether the data source is available 2) whether the gateway on-premises service is running using Windows Event Logs.
    5. This is the correlational id for latest refresh failure
    is
    f9030dd8-af4c-4225-8674-50ce85a770d0
    6.
    Refresh History error is –
    Errors in the high-level relational engine. The following exception occurred while the managed IDataReader interface was being used: The operation has timed out. Errors in the high-level relational engine. The following exception occurred while the
    managed IDataReader interface was being used: Query timeout expired. 
    Any idea what could have went wrong suddenly, everything was working fine from last 1 month.
    Thanks,
    Richa

    Never mind, figured out there was a lock on SQL table which caused all the problems. Once I released the lock it PowerPivot refresh started working fine.
    Thanks.

  • Can we use session variables in BI publisher's Data Model SQL Query?

    Hi Experts,
    We need to implement Data level security in BI Publisher 11g.
    In OBIEE we do so by using session variables, so just wanted to ask if we can use the same session variables in BI Publisher as well
    ie can we include the where clause in the Data Models SQL Query like
    Where ORG_ID = @{biServer.variables['NQ_SESSION.INV_ORG']}
    Let me know your views on this.
    PS: We are implementing EBS r12 security in BI Publisher.
    Thanks

    Read this -> OBIEE 11g: Error: "[nQSError: 23006] The session variable, NQ_SESSION.LAN_INT, has no value definition." when Creating a SQL Query using the session variable NQ_SESSION.LAN_INT in BI Publisher [ID 1511676.1]
    Follow the ER - BUG:13607750 - NEED TO BE ABLE TO SET A SESSION VARIABLE IN OBIEE AND USE IT IN BI PUBLISHER
    HTH,
    SVS

  • How to sort data in cl_gui_alv_tree class?

    Hi,
    I thought that since this object uses an alv grid that the standard sort functionality would exist.  Now that I've developed most of the code, I realize that there is no native sorting functionality.
    Is there some way I can make use of the Superclass CL_ALV_TREE_BASE?
    It has some methods that are "Private", "Instance"  - I'm still a rookie at OO programming in SAP so I'm not sure how best to approach the situation.
    As I see it, I have a few options:
    1)  Manually manage sorting by providing an ascending and descending button/icon on the toolbar and then delete and rebuild the nodes in the tree.
    2)  Manually track the data along with the nodekeys and then use method MOVE_NODE to reposition the data in the tree
    3)  Clone these objects and somehow find the code that is causing the sort options to be suppressed in the toolbar.
    Has anyone built any applications using CL_ALV_TREE_BASE that permit sorting?
    Please don't waste my time by pasting in the links to all the SAP online help for ALV and expect to get points.  Been there, done that.  If there is a particular section that is of specific value, I'll happily study it and report my findings.  Particularly something that explains how to invoke the methods of a superclass and the difference between protected, public, and private.
    Mostly though, I really need a way to sort data in the CL_GUI_ALV_TREE class.
    Thanks

    Hi Ray,
    As far as I know, this will not work. I've had the same problem. The only solution I have found was to re-build the tree each time. It is easier than moving nodes around.
    You can take a look at the class cl_wa_notifications_wps - in case you have a PM or an A&D system.
    Ferenc

  • SAP MII 14.0 SP5 Patch 11 - Error has occurred while processing data stream Dynamic Query role is not assigned to the Data Server

    Hello All,
    We are using a two tier architecture.
    Our Corp server calls the refinery server.
    Our CORP MII server uses user id abc_user to connect to the refinery data server.
    The user id abc_user has the SAP_xMII_Dynamic_Query role.
    The data server also has the checkbox for allow dynamic query enabled.
    But we are still getting the following error
    Error has occurred while processing data stream
    Dynamic Query role is not assigned to the Data Server; Use query template
    Once we add the SAP_xMII_Dynamic_Query role to the data server everything works fine. Is this feature by design ?
    Thanks,
    Kiran

    Thanks Anushree !!
    I thought that just adding the role to the user and enabling the dynamic query checkbox on the data server should work.
    But we even needed to add the role to the data server.
    Thanks,
    Kiran

  • No data from BW-Query in BO-tools

    Hello all
    On a newly installed BO XI 3.1 with the SAP integration kit I cannot get data from my existing BW queries.
    For example, if I start Xcelsius and add my BW-system as connection I can get the structure of the query (headings) but no data is displayed, neither in the connection's preview tab nor in the web preview.
    The same happens if I create a QaaWS on this BW-query - I see the query headings, but not the actual data.
    The query shows data if I open it directly in my web browser and it's a really simple one: no variables, no extras, only a few columns and rows.
    I use SAP BW 7.01 SP6, XI 3.1 12.3.3 and XCelsius 2008 5.3.4
    In SAP BW my user has SAP_ALL as well as BOE Admin & Content producer roles.
    I'm relatively new to BO products so I have no idea where to start looking for the cause. Please help!
    BR
    Kanan

    Hi
    After I found the document "Using Xcelsius 2008 with SAP NetWeaver BW" (http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10ad2489-8956-2d10-f8ab-ed4cce2766da?quicklink=index&overridelayout=true) and followed the steps it works.
    It seems as if the error was not in the system but in front of it - a typical case of RTFM, although the manuals are not always easy to find.
    sorry & thanks.
    BR
    Kanan

  • Key date for a query

    Dear All,
    I have created a customer exit variable on key date of a query.
    With this input variable i am first asking user to input one particular date say he enters 31.12.2010 then i am trying to add 1 more day to it and making it 01.01.2011.
    I have put a break point in the code but it does not stop the processing there.. report executes directly taking the first user input.
    I want to add 1 more day to the user entered date and this modifiied date should be the input date for key date field.
    Below is my code.
      WHEN 'ZCAL_DAY_EXT'.
        IF I_STEP = 2. "after the popup
          LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
          WHERE VNAM = 'ZCAL_DAY_EXT'.
            CLEAR L_S_RANGE.
          ENDLOOP.
          DATA: v_temp like sy-datum.
          v_temp = loc_var_range-low.
          v_temp = v_temp + 1.
          L_S_RANGE-LOW = v_temp.
          L_S_RANGE-SIGN = 'I'.
          L_S_RANGE-OPT = 'EQ'.
          APPEND L_S_RANGE TO E_T_RANGE.
        ENDIF.
    Do let me know where am i going wrong? Or is it we cannot use customer exit with Key date.
    Thanks & Regards,
    Anup
    Edited by: Anup Chaudhari on Aug 2, 2011 7:16 AM

    Hi Anup,
    Basically I_STEP = 1 is used for populating the default value which will be shown on selection screen and I_STEP = 2 is the step in which you does the processing on variable values which are entered on selection screen.
    I am surprised that your internal table is empty, actually it is supposed to contain all the variable values which are entered in I_STEP = 1.
    Can you try to add some more variables along with the current variable and check whether their value is coming in the internal table or not?
    Finally what you can try is get the user input date in one variable and then create another customer exit variable in which you will calculate the new value and use this variable in Key date, the problem might be that we are trying to modify the same variable, actually it should not be the problem but I have no clue what is happening and you can just try this alternative.
    Regards,
    Durgesh.

  • Oracle Forms - How can I create a Data Block with query

    Dear friends I have a question, I couldn't do this..
    I have a sql query, I want to show the datas of the query.. How can I do this. ?
    Data Block Wizard wants a table, view or stored procedure, but I have a query, how can I create a data block with my query.. I m waiting your helps..? Please...
    Semih

    Hi,
    You have two options
    1. create a view and base the block on the view
    2. create a block with a query Data Source Type of 'FROM clause query'
    Hope this helps
    Neil

  • "Source not found" Error creating URL Data control with query parameters

    Hi,
    I have a restful service for which i want to create a URL data control. I am able to create the URL data control successfully when i am not passing any parameters in the Source field. But if i am specifying the parameters in the source field like this Department=##ParamName##, something weird is happening. After giving the param string in the Source field, it asks for default param value to test the url. It tests the url successfully. After that i select XML as the data format in which i am mentioning the xsd like this . "file:///C:/..../something.xsd" . And this is when i am getting the error. "Invalid Connection. The source is not found". I am giving exactly same path for xsd which i gave while creating URL data control without query parameters. Infact i was able to create the URL data control with query parameters successfully till afternoon. after that it started giving me this error all of a sudden. Infact as soon as i was able to create a URL data contol with query parameter successfully, i took a backup of the application before moving further. But even that backup is not working now.
    As far as i understand, i dont think there will be any change in xsd if query params are passed to a web service. Please correct me if i am wrong.
    Just dont know what could be the issue. Please help
    Thanks

    Hi,
    xsd is used for the URL service to know what the returned data structure is so it can create the ADF DC metadata
    Frank

  • Where to get BW Metadata: owner, creation date, change date of a query / WS

    Hello,
    I need a report over the existing queries / worksheets and the owner, creation date, change date of a query etc.
    You see some of the information when you go over query properties in the query designer. But you see only the information of one (the opened) query. And you have to do this for every query ...
    My idea is to go over BW Metadata in the technical content.
    Here is the cube BW Metadata 0BWTC_C08
    (The InfoCube BW Statistics u2013 Metadata contains metadata from the Metadata Repository.)
    Is this the way to do it? Or any other suggestions u2026
    Can I get infos about used structures , etc over this way
    Thanks Markus

    I had to work on an other subject:
    But now the source of information is clear:
    RSRREPDIR - index of all queries
    RSZELTDIR -  index of all queries-components
    RSRWORKBOOK - Verwendungsnachweis für Berichte in Workbooks
    RSRWBINDEX - List of binary large objects (Excel workbooks)
    RSRWBINDEXT - Titles of binary objects (Excel workbooks) in InfoCatalog
    The tables are to join over
    RSRREPDIR.COMPUID  = RSZELTDIR.ELTUID
    RSZELTDIR.TEXTLG  contains the description
    RSRWORKBOOK.GENUID  = RSRREPDIR.GENUID
    RSRWBINDEXT and RSRWBINDEX are connected over WORKBOOKID
    I'd like to put the information of all of this tables in a cube and define a query on it.
    I have to define new datasource, infosource to get the data in the cube.
    Right?
    Now i see some existing datasource objects in the technical content.
    0TCTQUERID, 0TCTQUERID_TEXT, 0TCTQUERY, 0TCTQUERY_TEXT
    I can't open them to look in. But they might be helpfull. Anybody used them?
    Markus

Maybe you are looking for

  • Requirement to add new field in Location Tab of Service order

    We have a requirement in which it is needed to add anew field in Location Tab of Equipment and Service order. For Equipment part , we have added the field via Enhancement ITOB0001 and activating the field via "Set View Profile for Technical Objects".

  • E1 access problem in SRST

    Hi, I upgraded the IOS and the IP Phone are registered, but for outgoing calls not works. I made a call using CSIM command and the call works. The router are connect to PSTN by E1 PRI.Pls. see the SRST config: call-manager-fallback max-conferences 8

  • Groupwise Error [e811] Object not in database.

    A user is getting the following message when trying to open messages in a Client 7.0.3 folder: Groupwise Error [e811] Object not in database. Gwcheck shows no errors. The agent logs show no errors. This error just pops up in the client. Goes into end

  • Unwanted light blue background suddenly printing on everything. Help!

    I have PSE 8 and an Epson Stylus R1900 and Mac 10.6.8 . Until recent when I created a new blank file in PSE, selecting for instance a preset like photo 4 x 6 landscape choosing a white background content and then add my digital images /layers etc and

  • Adobe Flash Player Update Problem

    When I go to install the new Flash Player update on my Mac OS X I go through all the normal steps but when it begins to install it stays stuck at around 25% and won't move. It just says downloading. After a while of staying still it just says connect