MDX query - need to run different query (where clause) on mondays

The below query works OK and uses the substitution variable CurrentWeek in the WHERE clause, but I have one shortcoming that I need your help for:
The query works fine for all days but mondays. On Mondays I need the query to fetch numbers from last week (as opposed to current week) as the query returns null as the cubes have no data for current week on mondays. Hence I need to change the where clause to use substitution variable LastWeek, or in some other way run a different query on mondays. I have another substitution variable called WeekDay which I can use to test which day of the week it is, but I am not sure of the syntax I need to use to test for day of week and then have the query use different substitution variables as a result of this test.
Please help.
Henning Strand
SELECT NON EMPTY {[Measures].[meas_sg]} ON COLUMNS,
NON EMPTY {[Kunde],[Kunde].[KU01],[Kunde].[KU02],[Kunde].[KU03],[Kunde].[KU04]} ON ROWS
FROM MIFS.MIFS
WHERE ([Marked].[Dagligvare],[Tid].[&CurrentWeek])

Or to go off of Sean's suggestion, programmatically change the value of the substitution variable, and leave the code alone.
Other thoughts -- have a load process to a single cell (sorry, my BSO roots are showing, but the concept is the same, load a single number) and then do a boolean test off its value -- 0 = Monday, 1 = the rest of the week.
Regards,
Cameron Lackpour

Similar Messages

  • SQL query needed to identify cancelled invoice where distribution lines

    SQL query needed to identify cancelled invoice where distribution lines Debit is not equal Credit line item in particular
    Is there a way from back end FROM ap_invoice_distributions_all where we can find for the cancelled invoice where distribution lines Debit is not equal Credit line item
    Regards,
    Prakash Ranjan

    Hello Prakash
    Can you please see if this query helps you?
    SELECT i.invoice_id, i.invoice_amount, nvl(sum(d.amount),0)
    FROM ap_invoice_distributions_all d, ap_invoices_all i
    WHERE i.org_id = <you org_id>
    AND i.invoice_id = d.invoice_id
    AND d.line_type_lookup_code not in ('PREPAY')
    AND i.cancelled_date IS NOT NULL
    GROUP BY i.invoice_id, i.invoice_amount
    HAVING (i.invoice_amount <> nvl(sum(d.amount),0))
    ORDER BY i.invoice_id asc
    Octavio

  • Query slow down when added a where clause

    I have a procedure that has performance issue, so I copy some of the query and run in the sql plus and try to spot which join cause the problem, but I get a result which I can figuer out why. I have a query which like below:
    Select Count(a.ID) From TableA a
    -- INNER JOIN other tables
    WHERE a.TypeID = 2;
    TableA has 140000 records, when the where clause is not added, the count return quite quick, but if I add the where clause, then the query slow down and seems never return so I have to kill my SQL Plus session. TableA has index on TypeID and TypeID is a number type. When TablA has 3000 records, the procedure return very quick, but it slow down and hang there when the TableA contains 140000 records. Any idea why this will slow down the query?
    Also, the TypeID is a foreign key to another table (TableAType), so the query above can written as :
    Select Count(a.ID) From TableA a
    -- INNER JOIN other tables
    INNER JOIN TableAType atype ON a.TypeID = atype.ID
    WHERE atype.Name = 'typename';
    TableAType table is a small table only contains less than 100 records, in this case, would the second query be more efficient to the first query?
    Any suggestions are welcome, thanks in advance...
    Message was edited by:
    user500168

    TableA now has 230000 records and 28000 of them has the TypeID 2.
    I haven't use the hint yet but thank you for your reply which let me to to run a query to check how many records in TableA has TypeID 2. When I doing this, it seems pretty fast. So I begin with the select count for TableA only and gradually add table to join and seems the query is pretty fast as long as TableA is the fist table to select from.
    Before in my query TableA is the second table to join from, there is another table (which is large as well but not as large as TableA) before TableA. So I think this is why it runs slow before. I am not at work yesterday so the query given in my post is based on my roughly memory and I forget to mention another table is joined before TableA, really sorry about that.
    I think I learn a lesson here, the largest table need to be in the begining of the select statement...
    Thank you very much everyone.

  • Expert mode query in View objects and appended where clause

    My company is Oracle Member Partner and we are developing enterprise web applications using Oracle database and BC4J.
    I have the following problem...
    When I enable EXPERT MODE option in View Object I have trouble appending to query statement in my client code.
    I need expert mode because I must use "SELECT DISTINCT" insted of "SELECT" in my query.
    It looks something like this:
    viewObject.setWhereClause("CLA_ID = " + claId);
    viewObject.executeQuery();
    SQL query from View Object becomes sub-query and fails to execute:
    select * from (original view object query) where (... appended where clause)
    Order by part of the query causes sql errors because original query is now sub-query.
    Is there any way around this?

    I tried creating an expert mode SQL query:
    SELECT DISTINCT EMPNO, ENAME FROM EMP.
    Then at runtime I do:
    vo.setWhereClause("ENAME LIKE '%'||?||'%');
    vo.setWhereClauseParam(0,'A');.
    and this works fine. The trick is that since expert-mode view objects get wrapped as inline views (to allow runtime appending of WHERE clause, actually), you need to select any column in the select statement to which you want to later refer in a dynamically-appended where clause.
    If you want to prevent the inline-view wrapping, you can write the following code in your view object's ViewObjectImpl subclass to force the VO to NOT be treated as an expert-mode SQL VO.
      // Goes in your view object impl subclass
      public void create() {
         // Force this VO to NOT be treated as an expert-mode SQL, so that
         // its query does not get wrapped as an inline view.
         getViewDef().setFullSql(false);
      }I used this trick above to create an expert mode query like:
    SELECT DISTINCT deptno FROM empand then at runtime I add a dynamic where clause that refers to a column
    in EMP that is not in the select list like this:
        ViewObject vo = am.findViewObject("View1");
        vo.setWhereClause("ename like '%A%'");
        vo.executeQuery();
        System.out.println(vo.first().getAttribute(0));and this causes the query to come out as:
    SELECT DISTINCT deptno FROM emp WHERE ename like '%A%'.
    instead of:
    SELECT * FROM (SELECT DISTINCT deptno FROM emp) QRSLT WHERE ename like '%A%'which would cause an error due to the fact that ename is not in the select list of the original (wrapped, inline) query.

  • Query for Find Mode Fails-AutoGenerated WHERE clause missing quotation mark

    Using Oracle JDev 10.1.3.2. In 'Find Mode' the query execution fails.
    The error shown below is caused by the WHERE clause statement. The column name is quoted in the database but the code generated by the ADF framework does not use quotes. As a result the column name is illegal. Is there a way to hint to the ADF framework to ALWAYS use quotation marks?
    (oracle.jbo.SQLStmtException) JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (SELECT "PLATE","WROW","WCOL","WFIELD","AVGNUC.NUC_CELL_INTENSITY","MEDNUC.NUC_CELL_INTENSITY","AVGORG.INCLUSION_BCKG_INTE","MEDORG.INCLUSION_BCKG_INTE","MEDORG.COUNT","MEDORG.SPACING","MEDORG.NEIGHBOR_COUNT" FROM ICSUMSTAS_1888_295) QRSLT WHERE ( ( (MEDORG.COUNT >0) ) )

    It is true that these are not the most column 'friendly' names, but they are what they are. In the database these columns are quoted and they must be so in order for the query to work correctly.
    The suggestion of directly manipulating the View Criteria is a good one and I have implemented a solution based on it but it's cumbersome. Here is how it works:
    First, use the default query mode UI to add new View Criteria. If you were to execute the query at this point it would fail due to the columns names not being quoted. So, instead, implemented my own execute query button that first uses the View Criteria to create a properly quoted WhereClause for the ViewObject.
    I then reset the ViewCriteria (or they will interfere with the WhereClause), set the custom constructed WhereClause on the ViewObject, and re-execute the query. The cumbersome part is that I have to create my own parser for user input to write a valid WhereClause. And when the user uses query mode again the previously set ViewCriteria have been reset (which is annoying, and not the typical query mode behavior which might confuse the user)
    below are some of my code snippets:
    * This action is triggered by clicking the FIND button on the UI.
    * It uses a combination of the ViewCriteria default UI and custom code that processes
    * user input into a whereClause for the ViewObject
    private void jbFind_actionPerformed(ActionEvent e) {
    jbAddRow.setEnabled(false);
    //reset old where clause
    System.out.println("OLD WHERE:"+myView.getWhereClause());
    myView.setWhereClause(null);
    String customWhere=getCustomWhere();
    /* The case for null and blank View Criteria is tested below
    * when there are blank ViewCriteria the sequence (--) is generated from getCustomWhere
    * Note the use of contains instead of equals
    * The use of equalIgnoreCase etc for unexplained reasons seem to fail to detect when customWhere is (--)
    if(customWhere==null||customWhere.contains("(--)")){
    return;
    }else{
    /*remove ViewCriteria because they can not handle special Column names
    * That's why we go into the trouble of creating our own find function
    myView.getViewCriteria().removeAllElements();
    myView.setWhereClause(customWhere);
    myView.executeQuery();
    jUNavigationBar1.doAction(JUNavigationBar.BUTTON_EXECUTE);
    jTable1.revalidate();
    private String getCustomWhere(){
    StringBuffer custom=new StringBuffer();
    ApplicationModule am = (ApplicationModule) panelBinding.getApplication().getDataProvider();
    DCJboDataControl jbodc = new DCJboDataControl(am);
    JUIteratorBinding iterBinding = new JUIteratorBinding(jbodc,myView );
    int criteriaCount=iterBinding.getViewCriteria().getRowCount();
    //Validation when no ViewCriteria are defined
    if (criteriaCount==0){
    System.out.println("ViewCriteria Count: "+criteriaCount);
    return null;
    }else{
    System.out.println("ViewCriteria Count: "+criteriaCount);
    int attr=iterBinding.getViewCriteria().getCurrentRow().getAttributeCount();
    int criteriaRows=iterBinding.getViewCriteria().getAllRowsInRange().length;
    String[] attrNames=iterBinding.getViewCriteria().getCurrentRow().getAttributeNames();
    for (int r=0;r<criteriaRows;r++)
    {custom.append("(");
    for (int k=0;k<attr;k++){
    if(iterBinding.getViewCriteria().getRowAtRangeIndex(r).getAttribute(k)!=null){
    custom.append("(\""+attrNames[k]+"\"");// LIKE '"+(String)iterBinding.getViewCriteria().getRowAtRangeIndex(r).getAttribute(k)+"') AND ");
    //trim white space
    String attrK=((String)iterBinding.getViewCriteria().getRowAtRangeIndex(r).getAttribute(k)).trim();
    String qual=attrK.substring(0,1);
    if(qual.equalsIgnoreCase(">")||qual.equalsIgnoreCase("<")||qual.equalsIgnoreCase("=")||qual.equalsIgnoreCase("!")){
    custom.append(" "+qual+"'"+attrK.substring(1)+"') AND " );
    }else{
    custom.append(" LIKE '"+(String)iterBinding.getViewCriteria().getRowAtRangeIndex(r).getAttribute(k)+"') AND ");
    }custom.append("--");
    custom.append(")");
    custom.append(" OR ");
    }//end criteria rows
    custom.append("--");
    //now need to remove terminal AND and OR tagged with --
    String cleanWhere=custom.toString().replaceAll("AND --","").replaceAll("OR --","");
    System.out.println("NEW CUSTOM WHERE: "+cleanWhere);
    return cleanWhere;
    }

  • Permissions needed to run tarantella query audit?

    Hi
    I'm trying to run the "tarantella query audit ..." command to check for log file entries, using the account I use for all sgd admin.
    I've never done this before, and I get the error "you do not have permission to run this script" - can't find anything in the admin guide relating to specific permissions for this option, what am I missing?
    Thanks
    mrtng

    I did a quick test in my environment and found the runbook worked fine when run normally, but threw an access denied error when using runbook tester (my account is admin also). Just reinforcing to me that runbook tester is not a very useful tool.
    To troubleshoot, I'd try a couple changes:
    Create a new runbook with only the Run Program activity in it, and hard code the robocopy command that worked in the command line in the Command field
    Shouldn't need to specify server name if running locally on runbook server
    Leave everything else in the activity at defaults (no run as account in Advanced, and use service account in Security)
    Make sure activity-specific published data logging is enabled for the runbook
    Temporarily
    enable trace logging for Orchestrator remoting service, policymodule, and runbook service
    Then check in and run, and see if it works or there is more info in the trace logs.
    Has this server been "hardened" with any nonstandard policies or configuration? If so would want to peel those off to eliminate some kind of lockdown as the issue.
    Runbook:
    Noah Stahl | Automys |
    Downloadable Microsoft automation examples and solutions

  • Need modify Running total query

    CREATE TABLE DET
    (DDT DATE,
    DNO NUMBER,
    DCODE VARCHAR2(6),
    DAMOUNT NUMBER,
    DINST NUMBER);
    INSERT INTO DET VALUES (TO_DATE('01012010','DD/MM/YYYY'),7,1946,19674.5,NULL);
    INSERT INTO DET VALUES (TO_DATE('08012010','DD/MM/YYYY'),8,1574,4800,NULL);
    INSERT INTO DET VALUES (TO_DATE('08012010','DD/MM/YYYY'),8,1574,50000,208.333);
    INSERT INTO DET VALUES (TO_DATE('08012010','DD/MM/YYYY'),9,1835,31600,208.333);
    INSERT INTO DET VALUES (TO_DATE('08012010','DD/MM/YYYY'),6,1924,50000,232.558);
    INSERT INTO DET VALUES (TO_DATE('02022010','DD/MM/YYYY'),9,1835,5000,NULL);
    INSERT INTO DET VALUES (TO_DATE('02022010','DD/MM/YYYY'),9,1835,31600,131.667);
    INSERT INTO DET VALUES (TO_DATE('05022010','DD/MM/YYYY'),8,1574,50000,208.333);
    INSERT INTO DET VALUES (TO_DATE('10022010','DD/MM/YYYY'),6,1924,50000,232.558);
    INSERT INTO DET VALUES (TO_DATE('01032010','DD/MM/YYYY'),8,1574,50000,208.333);
    INSERT INTO DET VALUES (TO_DATE('01032010','DD/MM/YYYY'),6,1924,50000,232.558);
    i have this query ;
    SCOTT@orcl>select ddt,
      2  dno,
      3  dcode,
      4  newdamount damount,
      5  dinst,
      6  newdamount-nvl(dinst,0) run_tot
      7  from(
      8  select ddt,
      9  dno,
    10  dcode,
    11  damount,
    12  dinst,
    13  decode(nvl(to_number(to_char(ddt,'MM'))-1,0),0,damount,
    14  damount-nvl(dinst,0)*(to_number(to_char(ddt,'MM'))-1)) newdamount
    15  from det
    16  order by ddt)
    17  where dcode = '1835'
    18  order by ddt,dno,damount,dinst nulls first;
    it returns this result;
    DDT               DNO DCODE     DAMOUNT      DINST    RUN_TOT
    08/01/2010          9 1835        31600    208.333  31391.667
    02/02/2010          9 1835         5000                  5000
    02/02/2010          9 1835    31468.333    131.667  31336.666
    The results last row should appear like this;
    02/02/2010          9 1835    31391.667    131.667  31260 DAMOUNT for the row 02/02/2010 (where DINST > 0 ) should be 31391.667,(closing RUN_TOT of january)
    and NOT 31468.333.
    The above query logic could be enitrely wrong, because the criteria laid assuming that the instalment remains same every month.
    Please someone who is well-verse with Lag or Sum ..Over analytic function, correct my code.
    TY.

    user613563 wrote:
    Your query entirely missed one row with DAMOUNT 5000.
    i expect the result to be;
    DDT               DNO DCODE     DAMOUNT      DINST    RUN_TOT
    08/01/2010          9 1835        31600    208.333  31391.667
    02/02/2010          9 1835         5000                  5000
    02/02/2010          9 1835    31391.667    131.667  31260
    Well, i for one am not following the logic here, but this will give you the results you've posted (why doesn't the row with damount = 5000 factor in to the 'running total' in any way shape or form?)
    select
      ddt, dno, dcode, damount, dinst, resolved
    from
      select
        ddt, dno, dcode, damount, dinst,
        case when lag(trunc(ddt, 'MM')) over (order by ddt asc) != trunc(ddt, 'MM')
        then
          lag(damount-dinst) over (order by ddt asc) - dinst
        else
          damount-dinst
        end as resolved
      from det
      where dcode = '1835'
      and dinst is not null
        union all
      select
        ddt, dno, dcode, damount, dinst,
        damount as resolved
      from det
      where dcode = '1835'
      and dinst is null
      order by ddt asc, dinst nulls first
    )Edited by: Tubby on Jan 11, 2010 2:47 PM
    fixed the not equals sign since the forum eats less than / greater than symbols

  • Need Pay Run results Query in R12

    Hi Experts,
    Good morning to all.
    I have a requirement to display the fields like Payroll name,Payroll Period,element name and their values from pay run results.
    if anybody worked on this requirement please send me the select statement.
    Cheers
    Ram

    Does this help -
    select papf.employee_number,papf.full_name,ppa.effective_date,pp.payroll_name,
    pet.element_name,piv.name input_value,prrv.result_value
    from apps.pay_payroll_actions ppa, pay_assignment_actions paa,
    pay_payrolls_f pp,pay_run_results prr, pay_run_result_values prrv,
    pay_input_values_f piv,pay_element_types_f pet,
    apps.per_all_assignments_f paaf, apps.per_all_people_f papf
    where ppa.payroll_action_id = :payroll_action_id -- give your payroll_action_id
    and ppa.payroll_action_id = paa.payroll_action_id
    and ppa.payroll_id = pp.payroll_id
    and paa.assignment_action_id = prr.assignment_action_id
    and prr.run_result_id= prrv.run_result_id
    and prrv.input_value_id = piv.input_value_id
    and piv.element_type_id = pet.element_type_id
    and paaf.assignment_id = paa.assignment_id
    and paaf.person_id = papf.person_id
    and trunc(sysdate) between pp.effective_start_date and pp.effective_end_date
    and trunc(sysdate) between pet.effective_start_date and pet.effective_end_date
    and trunc(sysdate) between piv.effective_start_date and piv.effective_end_date
    and trunc(sysdate) between paaf.effective_start_date and paaf.effective_end_date
    and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
    order by employee_number;

  • Need to run a query to select # of counts based on each month

    Let's say I have a talble with 12 months, each month has some data.
    I want to run a select count(*) to get result of how many rows per month, like Jan----100, Feb---90, etc.
    How do I do that?
    Thanks in advance.

    user569151 wrote:
    Let's say I have a talble with 12 months, each month has some data.
    I want to run a select count(*) to get result of how many rows per month, like Jan----100, Feb---90, etc.
    How do I do that?
    Thanks in advance.May be like this:
    SELECT EXTRACT(MONTH FROM date_column),COUNT(*)
    FROM TABLE_NAME
    GROUP BY EXTRACT(MONTH FROM date_column);

  • Drill down needs to run different request

    An existing 5-level drill-down request must be changed to display a different report on drill-down from level 3 and produce this report through level 5. The different report differs in the columns it contains as well as the style and content of the graph. Since the different report is particular to the unique value at level 2, this value must be furnished to the level 3 report for filtering.
    I am new enough to the Siebel Analytics/Oracle OBIEE tool that I dont know where to begin looking for an approach to this. Any help you can provide will be appreciated.
    Cliff

    Hello Cliff, I dont have the BI in front of me but the concept is this:
    Instead of creating one report and drilling down the 5 levels
    You create 5 reports each report showing what you would want to see in that 'level'. Then instead of drilling down you navigate from the first repor tyou created to the second one and then from the second to the third etc.
    If you want the reports you navigate to to be filtered by the value you click on you can filter them as "is prompted".
    Navigation can be found on properties>column properties>column/value interaction i think in the criteria. You set the repoirt you want to navigate to when the user clicks on a field. You can also enter multiple navigaation targets.
    regards,
    Kostis

  • Column Security - Users can't see it, but need to use it in the query WHERE Clause

    I am looking at possible solutions (if any) on column security. We need to be able to restrict users from seeing certain columns, however, they will need these columns in the WHERE clause of queries.
    I thought about creating views, however, it would be a poor database design. Is there any way that this can be done on the database level. I know about Fine Granular Access Method, however, this just excludes the column completely. Which means that they can not be used in the WHERE clause.
    Any help would be greatly appreciated.
    Philip

    I too added 2nd apple ID when I tried to get Free app from apple store just to get to NONE on the credit card needed. It said it sent confirmation email to my new apple ID email that I have to confirm. Problem is I can not get to the new apple ID email account.  On my ipad it logs into my original email account and I see no where to log into another email account.  If I go to my laptop, the new apple ID I created does not let me log into email where apple said it was sent to.  It did not send to back up email account either.
    Can I log into 2 email accounts on my ipad where it says mail at bottom?
    Can I have 2 apple ids?
    If I created a 2nd apple id to get to NONE on credit card needed, can't I log into it also on another laptop in gmail?
    (won't let me)
    If I used my original apple id I created when I got my new ipad, it will not let me get free app without credit card, there is no where it says NONE needed. I am too new to apple to start with credit cards etc until I get use to it.

  • SQL query optimization by changinf the WHERE clause

    Hi all,
    I need to know about the SQL query performance improvement by changing the WHERE clause. Consider a query :
    select * from student where country ='India' and age = 20
    Say, country = 'India' filters 100000 records and age = 20 filters 2000 records if given one by one. Now can anyone tell if the performance of the query can be changed by changing the query like this :
    select * from student where age = 20 and country ='India'
    as first where clause will give 2000 results and next filter will be applicable on only 2000 rows. While in the former query first where clause would give 100000 rows and seconde filter, hence, would be applicable on 100000 rows???
    Kindly explain.
    Thanks in advance.
    Abhideep

    in general the order of the where condition should not be important. However there are a few exeptions where sometimes it might play a role. Sometimes this is called order of filter conditions. Among others it depends on RBO or CBO used, Oracle Version, Indexes on the columns, statistic information on the table and the columns, CPU statistics in place etc.
    If you want to make this query fast and you know that the age column has much better selectivity then you can simply put an index on the age column. An index on the country column is probably not useful at all, since to little different values are in this column. If you are already in 11g I would suggest to use a composite index on both columns with the more selective in first position.
    Edited by: Sven W. on Nov 17, 2008 2:23 PM
    Edited by: Sven W. on Nov 17, 2008 2:24 PM

  • How do you run a query to view duplicate records?

    I need to run a query with the query generator to produce a list of matching records. We have a problem whereby sales orders can come in by phone and email and therefore they sometimes get put on the system twice. I need to produce a query which picks up any orders where the CardCode and Document Value match, within say two days of each other.
    Please help?

    Hi Wendy Burt....
    Try This
    SELECT   COUNT(T0.[CardCode])as Duplicatecount, T0.[CardName], T0.[DocTotal] FROM ORDR T0
    WHERE T0.[DocTotal] IN ( select t1.doctotal from ORDR t1
    where t0.cardcode=t1.CardCode AND datediff(dd, t0.docdate,getdate())<=2)
    AND
    T0.CARDCODE IN ( select t1.CardCode from ORDR t1
    where t0.cardcode=t1.CardCode AND datediff(dd, t0.docdate,getdate())<=2)
    and t0.docstatus = 'O' and t0.doctotal >0
    GROUP BY  T0.[CardName], T0.[DocTotal]
    Regards,
    Kennedy

  • How to dynamically update columns in a where clause to a SQL query in OSB?

    Hi Gurus,
    I have a requirement where in we need to dynamically update a where clause to a SQL query in OSB(11.1.1.6.0).
    For example:
    If the JCA sql string is "select * from emp where emp_id = 100 and emp_status ='Permanent'" now i want to change this where clause and the new query has to be like "select * from emp where emp_name like 'S%' and emp_dept like 'IT' ". basically we need to change the where clause dynamically.
    We can also use "fn-bea:execute-sql()" in a xquery but I don't want to use this function as creates a new connection.
    I have done some home work and found out --> as per the DOC "http://docs.oracle.com/cd/E23943_01/dev.1111/e15866/jca.htm#OSBDV943" section: "25.5.2 JCA Transport Configuration for Proxy and Business Services", when a business service is created by using JCA, we can see Interaction Spec Properties under JCA Transport Tab. This will have a property "SqlString' and we can over ride it. But I am unable to figure out how to over ride the value. I have tried by using Transport Headers activity but no luck. Please guide me how to achieve this?
    Thanks in advance
    Surya

    I solved my problem.
    In my header renderer, I simply added a line to set the text to the object value "label.setText( (String) value );" (where label is an instance of a JLabel.
    Thank you to who took some time to think about it.
    Marc

  • How to add a dynamic where clause for a sql based VO with group by query?

    Hi,
    Here is my case, I have a sql query based VO with the query like "select status, count(*) StatusCount from my_table group by status". Now I used the following java code trying to dynamically add the where clause to my VO to filter the rows based the type attribute in my DB table.
    vo.setWhereClause("type='MyType1' ");
    vo.executeQuery();
    Then I got the sql syntax error. Looks like the ADF has added the where clause to the end of my sql so my sql becomes "select status, count(*) StatusCount from my_table group by status where type='MyType1' ". But what I expected was the correct syntax "select status, count(*) StatusCount from my_table where type='MyType1' group by status".
    Does anyone know if this is an ADF bug? Or is there any other way to achieve my goal?
    Thanks,
    Chunyang
    Edited by: Chunyang on Dec 13, 2012 9:09 PM

    Hi,
    When you use setWhereClause on the VO, it is applied on top of the VO query. I.e, assume your VO has the following query.
    select empno, ename from empNow, if you apply the where clause programatically, only the two attributes that you are using in the select statement could be used. I.e
    select * from (select empno, ename from emp) where ename='KING' - VALID
    select * from (select empno, ename from emp) where deptno=10  - INVALID (because the inner query - the one you've defined as query for your vo does not have deptno attribute selected)If you would need to set a dynamic where clause, you need to make them available in your select statement / use bind variables.
    -Arun

Maybe you are looking for