Empty WHERE Clause with AND condition after

I have a question concerning a SQL query that I am using for a report. I have converted an old report to Crystal Reports 2008 and the resulting SQL query no longer works.
After the conversion all the inner joins that were previously used in the report were moved to the FROM clause.
My resulting WHERE clause is as follows:
WHERE   AND
"TABLE"."TABLEKEY" IS NOT NULL
I get this error message:
ORA-00936 Missing expression
As you can see there WHERE clause has nothing before the AND condition because all the inner joins have moved to the FROM clause in the new version of Crystal Reports. I am fine with these inner joins moving but how do I take care of this empty condition.
Any help is appreciated.

Hi Joshua
Please go through the following SAP note which deals with similar type of issue.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333233313335333533393334%7D.do
Thanks

Similar Messages

  • Where clause with If condition

    Hi All,
    Oracle 11g
    I have the following table
    create table test_table ( firstname varchar2(500) , middlename varchar2(500) , lastname varchar2(500) );
    insert into test_table (firstname,middlename,lastname) values ('Peter',null,'Smith');
    insert into test_table (firstname,middlename,lastname) values ('Peter','John','Smith');
    insert into test_table (firstname,middlename,lastname) values ('Ralph','Sarah','Mike');
    insert into test_table (firstname,middlename,lastname) values ('Peter',null,'Mike');
    insert into test_table (firstname,middlename,lastname) values (null,'Peter','Mike');
    I need to run a query to get the records based on values on different fields. In other words in the above table if middle name is null then I want to search based on firstname , if middle name and firstname are null then search based on last name. Is it possible to do this in a single query ?
    For egs: if I search above table for Peter, I should get the following result
    'Peter','null','smith'
    'Peter','null','mike'
    'null','peter;,'mike'
    TIA,
    _Pete                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Morton,
    Got it. At first read, I came to the same conclusion. :-)
    Also, I was thinking about the index usage, if the table is indeed large and index need to be used FBI could be leveraged.
    vr
    Sudhakar B.
    sudhakar@ORCL>create index test_table_inx_fb on test_table( case
      2        when middlename is null
      3        and firstname is null then lastname
      4        when middlename is null
      5        then firstname
      6   else middlename
      7   end );
    Index created.
    sudhakar@ORCL>explain plan for select * from test_table
      2  where
      3  case
      4       when middlename is null
      5       and firstname is null then lastname
      6       when middlename is null
      7       then firstname
      8  else middlename
      9  end  = 'Peter'
    10  ;
    Explained.
    sudhakar@ORCL>SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1564031643
    | Id  | Operation                   | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |                   |     3 |  2268 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| TEST_TABLE        |     3 |  2268 |     2   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | TEST_TABLE_INX_FB |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access(CASE  WHEN ("MIDDLENAME" IS NULL AND "FIRSTNAME" IS NULL) THEN "LASTNAME"
                  WHEN "MIDDLENAME" IS NULL THEN "FIRSTNAME" ELSE "MIDDLENAME" END ='Peter')
    Note
       - dynamic sampling used for this statement
    19 rows selected.
    sudhakar@ORCL>

  • How can I pass multiple condition in where clause with the join table?

    Hi:
    I need to collect several inputs at run time, and query the record according to the input.
    How can I pass multiple conditions in where clause with the join table?
    Thanks in advance for any help.
    Regards,
    TD

    If you are using SQL-Plus or Reports you can use lexical parameters like:
    SELECT * FROM emp &condition;
    When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
    SELECT &columns FROM &tables &condition;
    But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
    Best of luck!

  • Generate a where clause with outer join criteria condition: (+)=

    Hi,
    In my search page, I use Auto Customization Criteria mode, and I build where clause by using get Criteria():
    public void initSrpQuery(Dictionary[] dic, String userName) {
    int dicSize = dic.length;
    StringBuffer whereClause = new StringBuffer(100);
    Vector parameters = new Vector(5);
    int clauseCount = 0;
    int bindCount = 1;
    for(int i=0; i < dicSize; i++){
    String itemName = (String)(dic.get(OAViewObject.CRITERIA_ITEM_NAME));
    Object value = dic[i].get(OAViewObject.CRITERIA_VALUE);
    String joinCondition = (String)dic[i].get(OAViewObject.CRITERIA_JOIN_CONDITION);
    String criteriaCondition = (String)dic[i].get(OAViewObject.CRITERIA_CONDITION);
    String criteriaDataType = (String)dic[i].get(OAViewObject.CRITERIA_DATATYPE);
    String viewAttributename = (String)dic[i].get(OAViewObject.CRITERIA_VIEW_ATTRIBUTE_NAME);
    String columnName = findAttributeDef(viewAttributename).getColumnNameForQuery();
    if((value != null) /*&& (!("".equals((String).trim())))*/){
    if(clauseCount > 0){
    whereClause.append(" AND ");
    whereClause.append(columnName + " " + criteriaCondition + " :");
    whereClause.append(++bindCount);
    parameters.addElement(value);
    clauseCount++;
    If I want to generate following where clause:
    select
    ,emp.name
    ,emp.email
    ,emp.salesrep_number
    ,comp.name
    ,gs.srp_goal_header_id
    ,gs.status_code
    ,gs.start_date
    ,gs.end_date
    from g2c_goal_shr_emp_assignments_v emp
    ,jtf_rs_salesreps rs
    ,xxg2c_srp_goal_headers_all gs
    ,cn_comp_plans_all comp
    where 1 = 1
    and rs.salesrep_id = gs.salesrep_id (+)
    and gs.comp_plan_id = comp.comp_plan_id (+)
    and gs.period_year (+) = :1 -- :1 p_fiscal_year
    How can I generate a where clause with outer join : gs.period_year (+) = :1 ? Will I get '(+)=' from get(OAViewObject.CRITERIA_CONDITION)?
    thanks
    Lei

    If you are using SQL-Plus or Reports you can use lexical parameters like:
    SELECT * FROM emp &condition;
    When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
    SELECT &columns FROM &tables &condition;
    But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
    Best of luck!

  • Where clause with a combination of And and Or statements - Basic question

    Hi,
    I have a where clause with a combination of And and Or statements... May I know which one would run first
    Here is the sample
    WHERE SITE_NAME = 'Q' AND ET_NAME IN ('12', '15') AND TEST_DATE > DATE OR SITE_NAME = 'E' AND ET_NAME IN ('19', '20')
    can you please explain how this combination works
    Thanks in advance

    Hi,
    This reminds me of a great story. It's so good, it probably didn't really happen, but it's so good, I'm going to repeat it anyway.
    IBM once had an "executive apptitude test" that they would give to job applicants. There were some questions you might call general knowlege or trivia questions, and each question had a weight (for example, answering an unimportant queestion might score one point, an important question might be 5 points.) One of the questions was "What is the standard width of a mobile home?", and the weight of the question was -20: answering the question correctly did serious harm to your score. The reasoning was that the more you knew about mobile homes, the less likely you were to be their kind of executive.
    Now, as to your question, the correct answer is: I don't know. I don't want to know. Mixing ANDs and ORs without grouping them in parentheses is a really bad idea. Even if you get it right, it's going to confuse the next person who has to look at that code. Use parentheses to make sure the code is doing what you want it to do.
    If you really want to find out, it's documented in the SQL language manual. Look up "Operators, prcedence"
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/operators001.htm#sthref815
    You can easily do an experiment, using scott.emp, or even dual, where
    WHERE  (x AND y)
    OR      zproduces different results from
    WHERE   x
    AND     (y OR z)

  • Dynamic where clause with loop statement

    Hi all,
    is it possible to use a dynamic where clause with a loop statement?
    Can you please advise me, how the syntax needs to be?
    Thanks for your suggestions,
    kind regards, Kathrin!

    Hi Kathrin,
               If u are in ECC 6.0, please go through the code...
              REPORT  zdynamic_select.
    TYPES:
      BEGIN OF ty_sales,
        vbeln  TYPE vbak-vbeln,            " Sales document
        posnr  TYPE vbap-posnr,            " Sales document item
        matnr  TYPE vbap-matnr,            " Material number
        arktx  TYPE vbap-arktx,            " Short text for sales order item
        kwmeng TYPE vbap-kwmeng,           " Order quantity
        vkorg TYPE vbak-vkorg,             " Sales organization
        kunnr TYPE vbak-kunnr,             " Sold-to party
        netwr TYPE vbak-netwr,             " Net Value of the Sales Order
      END OF ty_sales.
    DATA :
      gt_sales TYPE STANDARD TABLE OF ty_sales,
      wa_sales TYPE ty_sales.
    DATA: ob_select TYPE REF TO cl_rs_where.
    DATA: ob_from   TYPE REF TO cl_rs_where.
    DATA: ob_where  TYPE REF TO cl_rs_where,
          gv_source TYPE abapsource.
    START-OF-SELECTION.
    *Step 1 : Prepare the select fields.
      PERFORM zf_build_select.
    *Step 2 : Build the from clause for the select
      PERFORM zf_build_from.
    *Step 3 : Build the where clause for the select
      PERFORM zf_build_where.
    *Step 4 : Execute the dynamic select
      SELECT (ob_select->n_t_where)
          FROM (ob_from->n_t_where)
            INTO CORRESPONDING FIELDS OF TABLE gt_sales
            WHERE (ob_where->n_t_where).
      LOOP AT gt_sales INTO wa_sales.
        WRITE :   /5 wa_sales-vbeln,
                  15 wa_sales-vkorg,
                  20 wa_sales-kunnr,
                  40 wa_sales-netwr,
                  50 wa_sales-posnr,
                  60 wa_sales-matnr,
                  70 wa_sales-arktx,
                  90 wa_sales-kwmeng.
      ENDLOOP.
    *&      Form  zf_build_select
    FORM zf_build_select .
      CREATE OBJECT ob_select.
    *Build the table name/field name combination
    *Add Sales order header fields
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAK'
          i_fieldname = 'VBELN'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAK'
          i_fieldname = 'VKORG'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAK'
          i_fieldname = 'KUNNR'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAK'
          i_fieldname = 'NETWR'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
    *Add Sales order item fields
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAP'
          i_fieldname = 'POSNR'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAP'
          i_fieldname = 'MATNR'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAP'
          i_fieldname = 'ARKTX'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
      CALL METHOD cl_rs_where=>build_tabname_fieldname
        EXPORTING
          i_tabname   = 'VBAP'
          i_fieldname = 'KWMENG'
          i_sign      = '~'
        IMPORTING
          e_combined  = gv_source.
    *Add the where line
      CALL METHOD ob_select->add_line
        EXPORTING
          i_line = gv_source.
    ENDFORM.                    " zf_build_select
    *&      Form  zf_build_from
    FORM zf_build_from .
      CREATE OBJECT ob_from.
    *Add opening bracket
      CALL METHOD ob_from->add_opening_bracket
      CLEAR gv_source.
    *Add the join condition.This can be made
    *fully dynamic as per your requirement
      gv_source = 'VBAK AS VBAK INNER JOIN VBAP AS VBAP'.
    *Add the where line
      CALL METHOD ob_from->add_line
        EXPORTING
          i_line = gv_source.
      CLEAR gv_source.
    *Add the join condition.This can be made
    *fully dynamic as per your requirement
      gv_source = 'ON VBAKVBELN = VBAPVBELN'.
    *Add the where line
      CALL METHOD ob_from->add_line
        EXPORTING
          i_line = gv_source.
    *Add the closing bracket
      CALL METHOD ob_from->add_closing_bracket
    ENDFORM.                    " zf_build_from
    *&      Form  zf_build_where
    FORM zf_build_where .
      DATA :
      lv_field TYPE REF TO data,
      lv_field_low TYPE REF TO data,
      lv_field_high TYPE REF TO data.
      CREATE OBJECT ob_where.
    *Add the field VBELN : Sales Document
    *Use this method if you want to assign a single value to a field
    *Set the value for VBELN : Sales Document Number
    CALL METHOD ob_where->add_field
       EXPORTING
         i_fieldnm  = 'VBAK~VBELN'
         i_operator = '='
         i_intlen   = 10
         i_datatp   = 'CHAR'
       IMPORTING
         e_r_field  = lv_field.
    CALL METHOD ob_where->set_value_for_field
       EXPORTING
         i_fieldnm = 'VBAK~VBELN'
         i_value   = '0000120020'.
    *Use this method if you want to assign a range of values
    *Set a range for the Sales Document number
      CALL METHOD ob_where->add_field_between_2values
        EXPORTING
          i_fieldnm      = 'VBAK~VBELN'
          i_intlen       = 10
          i_datatp       = 'CHAR'
        IMPORTING
          e_r_field_low  = lv_field_low
          e_r_field_high = lv_field_high.
      CALL METHOD ob_where->set_2values_for_field
        EXPORTING
          i_fieldnm    = 'VBAK~VBELN'
          i_value_low  = '0000120020'
          i_value_high = '0000120067'.
    *Set the 'AND' Clause
      CALL METHOD ob_where->add_and.
    *Add the field MATNR : Material
      CALL METHOD ob_where->add_field
        EXPORTING
          i_fieldnm  = 'MATNR'
          i_operator = '='
          i_intlen   = 18
          i_datatp   = 'CHAR'
        IMPORTING
          e_r_field  = lv_field.
    *Set the value for the Material field
      CALL METHOD ob_where->set_value_for_field
        EXPORTING
          i_fieldnm = 'MATNR'
          i_value   = '000000000050111000'.
    *Set the 'AND' Clause
      CALL METHOD ob_where->add_and
    *Add the field VKORG
      CALL METHOD ob_where->add_field
        EXPORTING
          i_fieldnm  = 'VKORG'
          i_operator = '='
          i_intlen   = 4
          i_datatp   = 'CHAR'
        IMPORTING
          e_r_field  = lv_field.
    *Set the value for VKORG : Sales Organization
      CALL METHOD ob_where->set_value_for_field
        EXPORTING
          i_fieldnm = 'VKORG'
          i_value   = 'GMUS'.
    ENDFORM.                    " zf_build_where

  • SQL query in SQL_REDO Logminor showing where clause with ROWID

    SQL query in SQL_REDO Logminor showing where clause with ROWID. I dont wanted to use rowid but wanted to use actual value.
    OPERATION SQL_REDO SQL_UNDO
    DELETE delete from "OE"."ORDERS" insert into "OE"."ORDERS"
    where "ORDER_ID" = '2413' ("ORDER_ID","ORDER_MODE",
    and "ORDER_MODE" = 'direct' "CUSTOMER_ID","ORDER_STATUS",
    and "CUSTOMER_ID" = '101' "ORDER_TOTAL","SALES_REP_ID",
    and "ORDER_STATUS" = '5' "PROMOTION_ID")
    and "ORDER_TOTAL" = '48552' values ('2413','direct','101',
    and "SALES_REP_ID" = '161' '5','48552','161',NULL);
    and "PROMOTION_ID" IS NULL
    and ROWID = 'AAAHTCAABAAAZAPAAN';
    DELETE delete from "OE"."ORDERS" insert into "OE"."ORDERS"
    where "ORDER_ID" = '2430' ("ORDER_ID","ORDER_MODE",
    and "ORDER_MODE" = 'direct' "CUSTOMER_ID","ORDER_STATUS",
    and "CUSTOMER_ID" = '101' "ORDER_TOTAL","SALES_REP_ID",
    and "ORDER_STATUS" = '8' "PROMOTION_ID")
    and "ORDER_TOTAL" = '29669.9' values('2430','direct','101',
    and "SALES_REP_ID" = '159' '8','29669.9','159',NULL);
    and "PROMOTION_ID" IS NULL
    and ROWID = 'AAAHTCAABAAAZAPAAe';
    Please let me know solution/document which will convert SQL redo rowid value with actual value.
    Thanks,

    Please enclose your output within tag so that people here can read it easily and help you. Also the reason that why you want to remove rowid?
    Salman
    Edited by: Salman Qureshi on Mar 20, 2013 3:53 PM                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Mysterious where clause with japanese

    enviroment:
    PL/SQL Develope, Version 7.1.0.1337, Windows XP Professional 5.1 Build 2600 (Service Pack 2)
    Here is the problem, when i add a where clause with japanese, the data evaporated:
    SQL> select * from ja_test;
    EXECUTABLE_NAME DESCRIPTION
    XX00MRP0411C 需要供給データ作成マネージャ
    SQL> select * from ja_test j where j.description = '需要供給データ作成マネージャ';
    EXECUTABLE_NAME DESCRIPTION
    SQL>
    thanks in advance!

    Thanks for replies and Sorry for my rashness, maybe the following
    scripts could explain the problem more well. I create a table named
    ja_test with two fields(EXECUTABLE_NAME and DESCRIPTION), both of the
    type is varchar2, and there is only one record in the table,
    but the DESCRIPTION contains JAPANESE characters, when i use a where
    clause like this "where j.executable_name = 'XX00MRP0411C';", everything
    seems work fine, but when the where clase include JAPANESE characters
    like this "j.description = '需要供給データ作成マネージャ';", even if
    the "j.description" is copied form database, no records returned:
    SQL> select * from ja_test j where j.executable_name = 'XX00MRP0411C';
    EXECUTABLE_NAME DESCRIPTION
    XX00MRP0411C 需要供給データ作成マネージャ
    SQL> select * from ja_test j where j.description = '需要供給データ作成マネージャ';
    EXECUTABLE_NAME DESCRIPTION
    SQL> desc ja_test;
    Name Type Nullable Default Comments
    EXECUTABLE_NAME VARCHAR2(30)
    DESCRIPTION VARCHAR2(240) Y
    SQL>

  • Where clause with time stamp

    Hii,
    I have an issue with using where clause with time stamp. My requirement is to
    select * from driver_on_policy
    where last_change_datetime = '2001-03-06 19:00:06'
    date is in this form 6/3/2001 7:00:06 PM
    thnks
    sam

    If you want to use '6/3/2001 7:00:06 PM', then
    where last_change_datetime = to_timestamp('6/3/2001 7:00:06 PM','DD/MM/YYYY HH:MI:SS PM')If you can use a literal string in ANSI standard YYYY-MM-DD HH24:MI:SS format, then just
    where last_change_datetime = timestamp '2001-03-06 19:00:06' (That 'DD/MM' might need to be switched around to 'MM/DD' if you are in America.)
    Message was edited by:
    William Robertson

  • Where clause with conditions

    Hi all,
    I have a report that is to be filtered based on user input into a text field and drop down list.
    The goal is to let the user enter either an exact value (based off auto-complete functionality), or use the wildcard character, %
    This is where the drop down comes in. If they select value1, the autocomplete, exact value is used and the where clause would look like something below,
    select col1, col2, col3
    from table
    where :P1_FILTER in (select distinct col2 from another_table)If they select value2, then the where should process using the like function and %s. Something like,
    select col1, col2, col3
    from table
    where :P1_FILTER like (select distinct col2 from another_table)How can I take care of this in 1 where clause? I'm sort of stuck trying to figure it out.
    Thank you for any help.
    -Chris

    I don't believe the way you have it coded is correct.. Can you move it over o SQL Developer of the SQL Commands page in APEX and trying running your query? If it doesn't work there then your SQL is coded wrong.
    Since you are trying to have One or The Other condition be used for your query, I would think the Function returning Sql Code would be the obvious selection, but I could be wrong here...
    Thank you,
    Tony Miller
    Webster, TX
    A lady came up to me on the street, pointed at my suede jacket and said "Do you know a cow was murdered to make that jacket?"
    "I didn't know there were any witnesses", I replied " Now I'll have to kill you too"

  • Select with timestamp in the where-clause don't work after importing data

    Hello,
    I have to databases (I call them db1 and db2, they have the same datastructure) and exported some data from the table "rfm_meas"from db1. Later on I imported that dataset into the "rfm_meas"-table of db2. The table contains a col with the datatype "timestamp(6)" and checking the success of the import looks fine:
    (executed on db2)
    SELECT
    id,acqtime
    from
    rfm_meas
    WHERE
    box_id=1
    AND id>145029878
    Returns two rows:
    ID ACQTIME
    145029883 01.06.10 10:30:00,000000000
    145029884 01.06.10 10:50:00,000000000
    It seems there are valid timestamps as I expected.
    But if I now want to select all rows from box_id=1 which are newer than e.g. 25-may-2010 I would try this:
    SELECT
    id,acqtime
    from
    rfm_meas
    WHERE
    box_id=1
    AND acqtime>=to_timestamp('25-05-2010 17:10:00,000','DD-MM-YYYY HH24:MI:SS,FF3')
    And it returns ... nothing!? If I execute the same query on db1 it works correctly.
    I guess db1 and db2 has different codepages!?
    If I insert some rows from a PL/SQL script in db2 into the "rfm_meas"-table, querys like the one above works fine. Therefore i guess, during importing the data there must be something wrong, so I cann see the timestamp, but can't use it.
    How can i fix that? Any ideas?
    If someone need more details I will provide it.
    Regards
    Steffen

    check this link out
    Importing timestamp columns appears to use to_date instead of to_timestamp

  • "Invalid Column" on multiple where clauses with subqueries and cfqueryparam

    I'm seeing a behavior in the coldfusion cfquery that I'd like to find an exmplanation for .  I've got a query that does a subquery in the select portion and if I have multiple where lines, I get an "invalid column name" message for my second where clause, but only when I'm using cfqueryparam
    For example on the following I get "Invalid column name 'position_id'"
    SELECT   department_staff_tbl.*,
             (   SELECT   max(bookmark_id)
                 FROM     bookmarked_items_tbl
                 WHERE    item_id = department_staff_tbl.staff_id
             ) AS bookmark_id
    FROM     department_staff_tbl
    WHERE    department_id = <cfqueryparam value="#arguments.deptid#"  cfsqltype="cf_sql_integer">
    AND     position_id   = <cfqueryparam value="#arguments.posid#"   cfsqltype="cf_sql_integer">
    AND     staff_id      = <cfqueryparam value="#arguments.staffid#" cfsqltype="cf_sql_integer">
    If I change the order of my where clause so staff_id is first, then it tells me "department_id" is an invalid column.
    If I only have one where clause, it works.  (i.e. WHERE position_id = <cfqueryparam value="#arguments.posid#" cfsqltype="cf_sql_integer">).
    If I remove the where clause from my subquery (WHERE     item_id = department_staff_tbl.staff_id) it works.
    It also works if I remove the cfqueryparam from my where clause so that my query looks like this:
    SELECT   department_staff_tbl.*,
             (   SELECT   max(bookmark_id)
                 FROM     bookmarked_items_tbl
                 WHERE    item_id = department_staff_tbl.staff_id
             ) AS bookmark_id
    FROM     department_staff_tbl
    WHERE    department_id = #arguments.deptid#
    AND     position_id   = #arguments.posid#
    AND     staff_id      = #arguments.staffid#
    Any thoughts?

    I see two tables. So can the server. So, use qualified column-names.
    SELECT   department_staff_tbl.*,
             (   SELECT   max(bookmarked_items_tbl.bookmark_id)
                 FROM     bookmarked_items_tbl
                 WHERE    bookmarked_items_tbl.item_id = department_staff_tbl.staff_id
             ) AS bookmark_id
    FROM     department_staff_tbl
    WHERE    department_staff_tbl.department_id = <cfqueryparam value="#arguments.deptid#"  cfsqltype="cf_sql_integer">
    AND      department_staff_tbl.position_id   = <cfqueryparam value="#arguments.posid#"   cfsqltype="cf_sql_integer">
    AND      department_staff_tbl.staff_id      = <cfqueryparam value="#arguments.staffid#" cfsqltype="cf_sql_integer">

  • Expenditure Type LOV-- Adding where clause with controller extension- help

    Hi Gurus,
    I'm new to OA Framework and Java and I need to extend the controller for the expenditure type lov in iProcurement. I need to add a where clause to the VO to show only those expenditure
    types that will pass transactions controls based on the project and task.
    Name of the VO:ExpenditureTypeNoAwardLOVVO
    controller:oracle.apps.icx.lov.webui.ExpenditureTypeLovCO
    Original Query from the VO:
    select * from (SELECT et.expenditure_type, et.sys_link_start_date_active,
    et.sys_link_end_date_active, 1 as dummy_number
    FROM pa_expenditure_types_expend_v et
    WHERE et.system_linkage_function = 'VI'
    and (trunc(sysdate) between et.expnd_typ_start_date_active and
    nvl(et.expnd_typ_end_date_active, trunc(sysdate+1)))
    and (trunc(sysdate) between et.sys_link_start_date_active and
    nvl(et.sys_link_end_date_active, trunc(sysdate+1))) QRSLT
    ((WHERE UPPER(EXPENDITURE_TYPE) like UPPER(:1)
    AND (UPPER(EXPENDITURE_TYPE) like :2 or UPPER(EXPENDITURE_TYPE) like :3
    or UPPER(EXPENDITURE_TYPE) like :4 or UPPER(EXPENDITURE_TYPE) like :5)))
    I created a custom database function xxpa_check_txnctl which takes project_id, task_id and expenditure type as parameters and returns "Y" if that expenditure type is valid or
    returns "N" if it is not valid.
    What I need to add to the where clause of the above query is
    and *'Y' = ( select xxpa_check_txnctl(project_id,task_id,et.expenditure_type) from dual)* to the standard VO query so that only valid expenditure types will show up in the LOV for that
    project/task combination.
    I enabled the Debug Log from Diagnostics and able to see the values of project_id and task_id in the controller attached to the LOV (oracle.apps.icx.lov.webui.ExpenditureTypeLovCO) as shown
    below. Please tell me how I can add the where condition to the custom controller .
    I really appreciate your help.
    Thanks in Advance,
    Shree.
    ==========================================================================================
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:#Param# ProjectId=13
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:lov criteria item from dictionary in getLovItemNumber():
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:#Param# TaskId=796
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:VO used in ExpenditureTypeLovCO.java:
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:#Param# voName=ExpenditureTypeNoAwardLovVO
    ==========================================================================================
    Here is the code for the standard controller:
    ==========================================================================================
    package oracle.apps.icx.lov.webui;
    import com.sun.java.util.collections.ArrayList;
    import oracle.apps.fnd.common.VersionInfo;
    import oracle.apps.fnd.framework.OAApplicationModule;
    import oracle.apps.fnd.framework.OAViewObject;
    import oracle.apps.fnd.framework.webui.OAPageContext;
    import oracle.apps.fnd.framework.webui.beans.OAWebBean;
    import oracle.apps.fnd.framework.webui.beans.form.OAFormValueBean;
    import oracle.apps.fnd.framework.webui.beans.layout.OAListOfValuesBean;
    import oracle.apps.fnd.framework.webui.beans.message.OAMessageStyledTextBean;
    import oracle.apps.icx.por.req.webui.CheckoutInfoBaseCO;
    import oracle.jbo.domain.Number;
    public class ExpenditureTypeLovCO extends CheckoutInfoBaseCO
    public static final String RCS_ID = "$Header: ExpenditureTypeLovCO.java 120.1 2006/07/25 06:33:16 sudsubra noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: ExpenditureTypeLovCO.java 120.1 2006/07/25 06:33:16 sudsubra noship $",
    "oracle.apps.icx.lov.webui");
    public ExpenditureTypeLovCO()
    public void processRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
    super.processRequest(oapagecontext, oawebbean);
    java.util.Dictionary dictionary = oapagecontext.getLovCriteriaItems();
    Number number = getLovItemNumber(oapagecontext, dictionary, "ReqAwardId");
    Number number1 = getLovItemNumber(oapagecontext, dictionary, "ProjectId");
    Number number2 = getLovItemNumber(oapagecontext, dictionary, "TaskId");
    String s = null;
    if(number == null)
    s = "ExpenditureTypeNoAwardLovVO";
    } else
    ArrayList arraylist = new ArrayList(1);
    arraylist.add("getDefaultAwardId");
    Number number3 = (Number)executeServerCommand(oapagecontext, oapagecontext.getApplicationModule(oawebbean), "CheckoutLovSvrCmd", arraylist);
    if(isLoggingEnabled(oapagecontext, 1))
    logParam(this, oapagecontext, "defaultAwardId", number3, 1);
    if(number.equals(number3))
    s = "ExpenditureTypeWithDefaultAwardLovVO";
    OAViewObject oaviewobject = (OAViewObject)oapagecontext.getApplicationModule(oawebbean).findViewObject("ExpenditureTypeWithDefaultAwardLovVO");
    oaviewobject.setWhereClauseParam(0, number1);
    oaviewobject.setWhereClauseParam(1, number2);
    } else
    s = "ExpenditureTypeWithAwardLovVO";
    OAViewObject oaviewobject1 = (OAViewObject)oapagecontext.getApplicationModule(oawebbean).findViewObject("ExpenditureTypeWithAwardLovVO");
    oaviewobject1.setWhereClauseParam(0, number);
    if(isLoggingEnabled(oapagecontext, 1))
    logMsg(this, oapagecontext, "VO used in ExpenditureTypeLovCO.java:", 1);
    logParam(this, oapagecontext, "voName", s, 1);
    OAMessageStyledTextBean oamessagestyledtextbean = (OAMessageStyledTextBean)oawebbean.findIndexedChildRecursive("ExpenditureType");
    oamessagestyledtextbean.setViewUsageName(s);
    OAMessageStyledTextBean oamessagestyledtextbean1 = (OAMessageStyledTextBean)oawebbean.findIndexedChildRecursive("StartDate");
    oamessagestyledtextbean1.setViewUsageName(s);
    OAMessageStyledTextBean oamessagestyledtextbean2 = (OAMessageStyledTextBean)oawebbean.findIndexedChildRecursive("EndDate");
    oamessagestyledtextbean2.setViewUsageName(s);
    OAFormValueBean oaformvaluebean = (OAFormValueBean)oawebbean.findIndexedChildRecursive("ReqAwardId");
    oaformvaluebean.setViewUsageName(s);
    OAFormValueBean oaformvaluebean1 = (OAFormValueBean)oawebbean.findIndexedChildRecursive("ProjectId");
    oaformvaluebean1.setViewUsageName(s);
    OAFormValueBean oaformvaluebean2 = (OAFormValueBean)oawebbean.findIndexedChildRecursive("TaskId");
    oaformvaluebean2.setViewUsageName(s);
    ((OAListOfValuesBean)oawebbean).setViewUsageName(s);
    public void processFormRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
    super.processFormRequest(oapagecontext, oawebbean);
    ==========================================================================================

    Hi, I will try to look into the issue. I have also done customizations like this in past.
    To achieve this, we must read the Process request of CO properly and understand the places, where you have to make changes. In my case, I identify such places and also I couldn't extend the controller class. SO I took the code from standard CO, changed it at couple of places and created a class file with same code as standard CO but with changed at some places. After that I gave newly created CO name in personalization property, so that the page will follow newly created custom CO.
    So I would suggest to read the CO properly, to understand which line is doing what......

  • Using decode in where clause with user defined function

    Hi,
    I have a below query which is failing as the function in the decode taking all cust_account_id as input parameter instead of the one which satisfies the condition in the inner query.So please provide a solution how can i pass only the selected one.
    SELECT hca.cust_account_id
    FROM hz_cust_accounts hca
    WHERE hca.org_id=FND_PROFILE.value('ORG_ID')
    AND hca.cust_account_id = (SELECT DISTINCT hcasa.cust_account_id
    FROM hz_cust_acct_sites_all hcasa
    WHERE hcasa.cust_account_id =hca.cust_account_id
    AND hca.org_id = hcasa.org_id)
    AND DECODE (hca.status , 'A', xx_ar_cust_audit_pkg.get_ship_to_order_type(hca.cust_account_id)) IS NOT NULL
    Thanks,
    Abhilash

    I'm having to guess without access to your tables, but I think changing the IN to a join should produce the same results. The JOIN should be evaluated before applying the WHERE clause, so this may resolve your problem.
    SELECT hca.cust_account_id
    FROM   hz_cust_accounts hca
           INNER JOIN hz_cust_acct_sites_all hcasa
           ON    hcasa.cust_account_id = hca.cust_account_id
           AND   hca.org_id = hcasa.org_id
    WHERE  hca.org_id = FND_PROFILE.value('ORG_ID')
    AND    DECODE (hca.status , 'A', xx_ar_cust_audit_pkg.get_ship_to_order_type(hca.cust_account_id)) IS NOT NULLAlternately, you could next part of the query and break the DECODE into the parent so it is evaluated after the inner query. This is likely uglier from a performance standpoint, though:
    SELECT cust_account_id
    FROM
    SELECT hca.cust_account_id, hca.status
    FROM   hz_cust_accounts hca
    WHERE  hca.org_id=FND_PROFILE.value('ORG_ID')
    AND    hca.cust_account_id = (SELECT DISTINCT hcasa.cust_account_id
                                  FROM   hz_cust_acct_sites_all hcasa
                                  WHERE  hcasa.cust_account_id =hca.cust_account_id
                                  AND    hca.org_id = hcasa.org_id)
    WHERE DECODE (status , 'A', xx_ar_cust_audit_pkg.get_ship_to_order_type(cust_account_id)) IS NOT NULL;

  • Where Clause With Multiple Rows

    I am tracking Objects called Incidents. Incidents can be made up of an undetermined number of questions and answers, such that my table structure to store these incidents looks as follows:
    INCIDENT_ID     QUESTION_ID     ANSWER_ID
    10001             49100         100 ("YES")
    10001             49101         275 ("5 HOURS")
    10002             49100         102 ("NO")
    10002             49101         276 ("10 HOURS")I allow my users to enter complex queries, such as "give me all incidents where question 49100 equals YES AND question 49101 equals 5 or less, OR where 49100 equals NO and 49101 is greater than 5", etc...
    My problem is how to handle these types of complex queries. Right now, I bring all of the rows into a Java object, and then I can analyze the results using Java (this works elegantly and allows me to have very complex formulas).
    However, if I have to deal with millions of Incidents and Answers, bringing them all into Java seems to be very time consuming. I'd like to be able to handle everything in the database. Because I allow my users to enter the queries through a "query builder", I can't control how many conditions they might have. In other words, if I try to use inner queries in the WHERE clause, I may exceed limits.
    It would be easiest if I could translate this vertical table into a temporary horizontal table, and then run my query on this horizontal table. My problem is that some of my questions have 1000s of answers (where they might be picking from a large select list), and therefore I can't do sums and counts on all the choices in separate columns. If I try a bit field for each column, once again I can run out of space because of the 1000s of possible answers.
    Has anyone faced this issue before? What choices do I have to make this all work in the database without having to parse the results in Java?
    Michael

    I was under the impression that each medication uses a unique id itself (defined perhaps by the medical insurance industry) and that itemized lists contain that code. And thus the user can type in the code.
    If so then one could handle the interface using both of the following methods.
    - The user can type in the id (this is validated.)
    - The user can push a button to bring up a dialog that provides the list and also provides an intelligent search option. (Or the id field can just be an aspect of the intelligent search.)
    Even in a small doctor's office experienced users will probably know the common ids and it would be simpler for them to type that in. In a processing center this would be more important as the time to process each transaction directly impacts the bottom line. This becomes much more relevant when the users are paid bonuses based on how many transactions they process (and managers might get that as well.)

Maybe you are looking for