Where condition problem in select statement.

Hi,
I am trying to write select statement as below
  SELECT objectclas objectid FROM cdhdr INTO CORRESPONDING FIELDS OF TABLE ltab_chgdocu
                   WHERE objectclas IN ('STUE' , 'STUE_V')
                   AND   ( TCODE eq 'CS01u2019 or tcode eq u2019CS02u2019 or   tcode eq 'C201' or tcode eq 'C202' ) .
But I am getting the error like "literals that takes up more than one line or not permitted"
Please let me know whats wrong and correct me .
Thanks,
Vinay.

Hi Vinay,
Declare constants
constants : c_stue type CDOBJECTCL value 'STUE',
             c_stue_v type CDOBJECTCL value 'STUE_V',
             c_cs01 type sy-tcode value 'CS01',
             c_cs02 type sy-tcode value 'CS02',
             c_C201 type sy-tcode value 'C201',
             c_C202 type sy-tcode value 'C202'.
And replace your hardcoded values with these constants in your select query.
SELECT objectclas objectid FROM cdhdr INTO CORRESPONDING FIELDS OF TABLE it_tab
                                    WHERE objectclas IN (c_STUE , c_STUE_V)
                                                 AND ( TCODE eq c_CS01
                                                 or tcode eq c_CS02
                                                 or  tcode eq c_C201
                                                  or tcode eq c_C202 ).
Thanks & Regards
- Always Leaner

Similar Messages

  • Field symbols as Table name and in where condition in a select statement

    Hello All,
    I have a scenario where I need to get user input on table name and old field value and new field value. Then based on user input, I need to select the record from the database. The column name for all the tables in question is different in the database, however there data type is the same and have same values.
    I am not able to use a field symbol for comparing the old field value to fetch the relevant record in my where clause.
    I cannnot loop through the entire table as it has 10 millilon records, please advice on how to add the where clause as field symbol as the table name is also dynamically assigned.
    Here is my code:
    DATA: TAB       LIKE SY-TNAME,
          TAB_COMP1 LIKE X031L-FIELDNAME,
          TAB_COMP2 LIKE X031L-FIELDNAME,
          NO_OF_FLD TYPE N.
    DATA: BEGIN OF BUFFER,
            ALIGNMENT TYPE F,
            C(8000)   TYPE C,
          END OF BUFFER.
    FIELD-SYMBOLS: <WA>   TYPE ANY,
                  <COMP1> TYPE ANY,
                  <COMP2> TYPE ANY.
    GET TABLE NAME GIVEN BY USER IN LOCAL VARIABLE
      TAB = TAB_NAME.
    CREATE FIELD NAME BASED ON THE TABLE NAME ENTERED.
      CASE TAB_NAME.
      WHEN 'OIUH_RV_GL'.
          KEY FIELD
            TAB_COMP1  = 'GL_GL_SYS_NO'.
            NO_OF_FLD  = 1.
      WHEN 'OIUH_RV_OPSL'.
          KEY FIELD
            TAB_COMP1  = 'OPSL_GL_SYS_NO'.
            NO_OF_FLD  = 1.
      WHEN 'OIUH_RV_OTAX'.
          NOT THE ONLY KEY FIELD
            TAB_COMP1  = 'OTAX_GL_SYS_NO'.
            TAB_COMP2  = 'OTAX_TAX_POS_NO'.
            NO_OF_FLD  = 2.
      WHEN 'OIUH_RV_GTAX'.
          NOT THE ONLY KEY FIELD
            TAB_COMP1  = 'GTAX_GL_SYS_NO'.
            TAB_COMP2  = 'GTAX_TAX_POS_NO'.
            NO_OF_FLD  = 2.
      WHEN OTHERS.
            EXIT.
      ENDCASE.
    SET FIELD SYMBOL WITH APPROPRIATE TYPE TO BUFFER AREA.
    ASSIGN BUFFER TO <WA> CASTING TYPE (TAB).
    How to add where clause and remove the if condition in the select -- endselect
    SELECT * FROM (TAB) INTO <WA>. 
      ASSIGN COMPONENT TAB_COMP1 OF STRUCTURE <WA> TO <COMP1>.
      IF NO_OF_FLD = 2.
        ASSIGN COMPONENT TAB_COMP2 OF STRUCTURE <WA> TO <COMP2>.
      ENDIF.
      IF <COMP1> = OLD_SYS_NO.
        code for updating table would come here
          WRITE: 'MATCH FOUND'.
          EXIT.
      ENDIF.
    ENDSELECT.
    Please advice. Thanks much.
    Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:33 PM
    Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:34 PM
    Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:35 PM

    1. Create single column table for holding field name depending on the table entered.
    2. Take input from user: for e.g. table_name
    3. Using case load single column table with required fields
       for e.g.
      CASE TAB_NAME.
       WHEN 'OIUH_RV_GL'.
             Append 'GL_GL_SYS_NO' to KEY_FIELD --> KEY_FIELD is the single line internal table as mentioned in step 1.
       WHEN 'OIUH_RV_OPSL'.
             Append 'OPSL_GL_SYS_NO'.
       WHEN 'OIUH_RV_OTAX'.
             Append 'OTAX_GL_SYS_NO' to KEY_FIELD.
               APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
       WHEN 'OIUH_RV_GTAX'.
             Append 'GTAX_GL_SYS_NO' to KEY_FIELD.
               APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
       WHEN OTHERS.
          EXIT.
       ENDCASE.
       Now depending on the table name you have required column ready
    4. Create dynamic internal table using following sudo code
       Fill the fieldcatlog using the single column field table and DD03L table, See what all columns from DD03L you want to fill in field catlog table
       loop at internal table with all the fields.
        move it to field catalog.
        append field catalog.
       endloop.
    5. Pass this field catalog table to static method create_dynamic_table method
       DATA table TYPE REF TO DATA. --> data object for holding handle to dynamic internal table.
       call method cl_alv_table_create=>create_dynamic_table
       exporting
          it_fieldcatalog = fieldcatalog_tab
       importing
          ep_table = table.
    6. Now assign table reference to field symbol of type table.
       ASSIGN table->* to <field-tab>.
    7. Also create work area <field-wa> using refrence of table.
       create data object wa LIKE LINE OF <field-tab>.
       ASSIGN wa->* to <field-wa>.
    8. Also define field symbol for field name.
       for e.g. <field_name>
    4. Dynamic internal table is ready
    5. Now execute the select statement as follows:
       SELECT (KEY_FIELD)
         INTO <ITAB> --> created dynamically above
          FROM (TABLE_NAME)
         WHERE (WHERE).  --> WHERE is single line internal table having line type of CHAR72. So for every old value there will be one line
         Where condition is same as like we give in static way only difference in this case it will stored in internal table line wise.
        In this case you need to append all your where condition line by line in to WHERE.     
    5. To fill this dynamic internal table using ASSIGN COMPONENT <Comp_number> OF STRUCTURE <field-wa> TO <field-name>
       So in this case if first field of structure STRUCT1 is user_id then sudo-code will be
       loop at internal table containing list of fields into field_wa --> single column field table
           ASSIGN COMPONENT field_wa OF STRUCTURE <field-wa> TO <field>. "Here field_wa is wa area for single column internal table holding all the fieldnames.
           Now <field-name> points to user_id field. Move some value into it as nornally we do with variables.
           Move <your_new_value> to <field-name>. --> Assign new value
            or
            <field-name> = <your_new_value>.
       Endloop.
    6. After completing all the fields one row will be ready in <field_wa>.
       APPEND <field_wa> to <field_tab>.
    Hope this helps you.
    Thanks,
    Augustin.

  • Values from a Multi-Select in the where clause of a Select statement

    I have a web page that solicits query parameters from the user.
    The selections that the user makes will populate the WHERE clause of a Select statement.
    One of the controls on the page is a multi-select control.
    When this page posts, I would like to execute a Select statement wherein the selected values from this control appear in the .. Column IN ( <list here> ) portion of the WHERE clause.
    This is an extremely common scenario, but I cannot seem to locate a how-to or message thread that addresses this specific case.
    I have an idea that it may involve dynamic SQL or Execute Immediate, but cannot seem to pin down the answer.
    Any help would be greatly appreciated!

    anonymous - As illustrated here: Re: Search on a typed in list of values
    Scott

  • Problem with select statement using Ranges

    Hi Guys,
                   I have used Ranges and used a select statement for selecting those ranges but I am facing a problem.
    RANGES: r_doctyp for EDIDC-DOCTYP.
    r_doctyp-sign = 'I'.
    r_doctyp-option = 'EQ'.
    r_doctyp-low  = 'DEBMAS'.
    append r_doctyp.
    r_doctyp-sign = 'I'.
    r_doctyp-option = 'EQ'.
    r_doctyp-low  = 'MATMAS'.
    append r_doctyp.
    r_doctyp-sign = 'I'.
    r_doctyp-option = 'EQ'.
    r_doctyp-low  = 'PRICAT'.
    append r_doctyp.
    r_doctyp-sign = 'I'.
    r_doctyp-option = 'EQ'.
    r_doctyp-low  = 'ORDERS'.
    append r_doctyp.
    r_doctyp-sign = 'I'.
    r_doctyp-option = 'EQ'.
    r_doctyp-low  = 'INVOIC'.
    append r_doctyp.
    Select DOCNUM                                " IDoc number
           DOCTYP                                " IDoc Type
                 from  EDIDC into table IT_ZEDIDC
                 where CREDAT EQ s_credat-low
                 and   DOCTYP EQ r_doctyp        " IDOC Types
                 and   DIRECT EQ '1'.
    Here my select statement is only taking INVOIC.
    But my statement should take any document type.
    Thanks,
    Prasad.

    Hi...,
    Your following select statement is correct.
    Select DOCNUM                                " IDoc number
                DOCTYP                                " IDoc Type
                from  EDIDC into table IT_ZEDIDC
                where CREDAT IN s_credat
                and   DOCTYP IN r_doctyp        " IDOC Types
                and   DIRECT EQ '1'.
    Why you are not getting result..
    1. structure of the IT_ZEDIDC is having two fields DOCNUM , DOCTYP  with same data lengths. If not it should be...
    2. Order in the database table is must be similer to the order you maintained in the select statement.
    3. As you are hard coding the input ranges make sure about every letter.
    4. take a look at other where condition fields too.
    5. check the table of the ranges in debugging mode.
    6. why can't you declare separate work area and table for ranges...?
      like .... data: r_tab type range of <field>
                 data: wa_tab like line of r_tab.
    7. Use clear work area statement after the append statment.
    --Naveen Inuganti.

  • Dynamic where condition - Problem

    Hi All,
    I have a problem in a select statement where I use a dynamic condition.It gives me a dump
    SAPSQL_WHERE_PARENTHESES
    CX_SY_DYNAMIC_OSQL_SYNTAX.
    Please find the below code which I implemented.
      *SELECT * FROM ZXR5*
               WHERE (SOURCE).
    The value of SOURCE is 'MATNR EQ '000000000000200066'.
    When I checked the help, it is advised to use a CATCH exception which I did as below:
    TRY.
      *SELECT * FROM ZXR5*
               WHERE (SOURCE).
      CATCH cx_sy_dynamic_osql_error.
        MESSAGE `Wrong WHERE condition!` TYPE 'I'.
    ENDTRY.
    Now, the select statement gives an exception and is not executing to fetch the values.
    I need some input on the above issue. Any help on this would be greatly appreciated.
    Regards,
    Rajmohamed.M

    Hi Vijay,
    I tried the same and all the time, the select statement gives me an exception and wont proceed.
      TRY.
        SELECT * FROM ZXR5
                 INTO TABLE <L_ZXR5>
                 WHERE (SOURCE).
        CATCH cx_sy_dynamic_osql_error.
        MESSAGE `Wrong WHERE condition!` TYPE 'I'.
      ENDTRY.
    Regards,
    Raj

  • Using if logic in the where clause of a select statement

    I have a select clause. And in the select clause there is a variable all_off_trt that can be 'Y' or 'N'.
    In the where clause I want to make it so that if a form variable is checked and all_off_trt is 'Y' then
    exclude it else if the form variable isn't checked then select it no matter what all_off_trt is.
    Is there any way to include either and if statement or a case statement within the where clause to acheive this? If not is there another way of doing it?
    Basically I am looking for a case statement like this
    case
    when all_off_trt = 'Y' and mail_para.code = 'Y' then false
    else true
    end
    Message was edited by:
    Tugnutt7

    Ok, so that really doesn't solve my problem. I have 3 different fields that I need to do that with. Each combining in a select statement to print an email list, as well as other thing limiting the where clause.
    This is currently what I have, tested and working 100%.
    cursor email_cur is
         select unique p.email,s.all_off_trt,s.all_deceased,s.no_enroll
    from participant p, trialcom t, ethics s
    where p.status='A'
    and p.surname=t.surname
    and p.initials=t.initials
    and s.trial_cd = t.tricom
    and s.centre = t.centre
    and p.email is not null
    and (t.centre in (select code from mail_parameters where user_name=user and mail_para='CENTRE')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='CENTRE'))
    and (t.tricom in (select code from mail_parameters where user_name=user and mail_para='TRIAL')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='TRIAL'))
    and (t.role in (select code from mail_parameters where user_name=user and mail_para='ROLE')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='ROLE'))
    and (p.country in (select code from mail_parameters where user_name=user and mail_para='COUNTRY')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='COUNTRY'))
    and (t.represent in (select code from mail_parameters where user_name=user and mail_para='REPRESENT')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='REPRESENT'));
    This is in a program unit that runs when a button is clicked. At the end of that I need to add on the 3 case statements that help further narrow down the selection of emails to be printed. Then it prints the emails selected from this statement into a file. So it has to be done right in the select statement. The three table variables are the all_off_trt, all_deceased, and no_enroll. The form has 3 checkboxes. One for each, that when checked (giving the variable associated with the checkboxes a value of 'Y') excludes all emails that have a 'Y' in the coresponding table variable.

  • Problem with Select Statements

    Hi All,
    I have a performance problem for my report because of the following statements.
    How can i modify the select statements for improving the performance of the report.
    DATA : shkzg1h  LIKE bsad-shkzg,
             shkzg1s  LIKE bsad-shkzg,
             shkzg2h  LIKE bsad-shkzg,
             shkzg2s  LIKE bsad-shkzg,
             shkzg1hu LIKE bsad-shkzg,
             shkzg1su LIKE bsad-shkzg,
             shkzg2hu LIKE bsad-shkzg,
             shkzg2su LIKE bsad-shkzg,
             kopbal1s  LIKE bsad-dmbtr,
             kopbal2s  LIKE bsad-dmbtr,
             kopbal1h  LIKE bsad-dmbtr,
             kopbal2h  LIKE bsad-dmbtr,
             kopbal1su  LIKE bsad-dmbtr,
             kopbal2su  LIKE bsad-dmbtr,
             kopbal1hu  LIKE bsad-dmbtr,
             kopbal2hu  LIKE bsad-dmbtr.
    *These statements are in LOOP.
        SELECT shkzg SUM( dmbtr )
          INTO (shkzg1s , kopbal1s)
          FROM bsid
         WHERE bukrs = ibukrs
           AND kunnr = ktab-kunnr
           AND budat < idate-low
           AND shkzg = 'S'
           AND umskz EQ ''
         GROUP BY shkzg.
        ENDSELECT.
        SELECT shkzg SUM( dmbtr )
          INTO (shkzg1su , kopbal1su)
          FROM bsid
         WHERE bukrs = ibukrs
           AND kunnr = ktab-kunnr
           AND budat < idate-low
           AND shkzg = 'S'
           AND umskz IN zspgl
         GROUP BY shkzg.
        ENDSELECT.
        SELECT shkzg SUM( dmbtr )
          INTO (shkzg1h , kopbal1h)
          FROM bsid
         WHERE bukrs = ibukrs
           AND kunnr = ktab-kunnr
           AND budat < idate-low
           AND shkzg = 'H'
           AND umskz EQ ''
         GROUP BY shkzg.
        ENDSELECT.
        SELECT shkzg SUM( dmbtr )
          INTO (shkzg1hu , kopbal1hu)
          FROM bsid
         WHERE bukrs = ibukrs
           AND kunnr = ktab-kunnr
           AND budat < idate-low
           AND shkzg = 'H'
           AND umskz IN zspgl
         GROUP BY shkzg.
        ENDSELECT.
        SELECT shkzg SUM( dmbtr )
          INTO (shkzg2s , kopbal2s)
          FROM bsad
         WHERE bukrs = ibukrs
           AND kunnr = ktab-kunnr
           AND budat < idate-low
           AND shkzg = 'S'
           AND umskz EQ ''
         GROUP BY shkzg.
        ENDSELECT.
        SELECT shkzg SUM( dmbtr )
          INTO (shkzg2su , kopbal2su)
          FROM bsad
         WHERE bukrs = ibukrs
           AND kunnr = ktab-kunnr
           AND budat < idate-low
           AND shkzg = 'S'
           AND umskz IN zspgl
         GROUP BY shkzg.
        ENDSELECT.
        SELECT shkzg SUM( dmbtr )
          INTO (shkzg2h , kopbal2h)
          FROM bsad
         WHERE bukrs = ibukrs
           AND kunnr = ktab-kunnr
           AND budat < idate-low
           AND shkzg = 'H'
           AND umskz EQ ''
         GROUP BY shkzg.
        ENDSELECT.
        SELECT shkzg SUM( dmbtr )
          INTO (shkzg2hu , kopbal2hu)
          FROM bsad
         WHERE bukrs = ibukrs
           AND kunnr = ktab-kunnr
           AND budat < idate-low
           AND shkzg = 'H'
           AND umskz IN zspgl
         GROUP BY shkzg.
        ENDSELECT.

    >
    Siegfried Boes  wrote:
    > Please stop writing answers if you understrand nothing about database SELECTS!
    > All above recommendations are pure nonsense!
    >
    > As always with such questions, you must do an analysis before you ask! The coding itself is perfectly o.k., a SELECT with an aggregate and a GROUP BY can not be changed into a SELECT SINGLE or whatever.
    >
    > But your SELECTS mustr be supported by indexes!
    >
    > Please run SQL Trace, and tell us the results:
    >
    > I see 8 statements, what is the duration and the number of records coming back for each statement?
    > Maybe only one statement is slow.
    >
    > See
    > SQL trace:
    > /people/siegfried.boes/blog/2007/09/05/the-sql-trace-st05-150-quick-and-easy
    >
    >
    > Siegfried
    Nice point there Siegfried. Instead of giving constructive suggestion, people here give a very bad suggestion on using SELECT SINGLE combined with SUM and GROUP BY.
    I hope the person already look at your reply before he try using select single and wondering why he has error.
    Anyway, the most important thing is how many loop expected for those select statements?
    If you have like thousands of loop, you can expect a poor performance.
    So, you should also look at how many times the select statement is called and not only performance for each select statement when you're doing SQL trace.
    Regards,
    Abraham

  • How to pass the parameter in the where clause of the select statement

    Hi All,
    Iam getting one of the value from the Input otd and using this value i need to query one of the tables in oracle database and selected the table using the oracle eway otd like shown below .
    otdRISKBLOCK_1.getRISKBLOCK().select() .
    where clause in side the select takes a string parameter as Iam getting the string parameter from the input otd and passing this to where clause by creating a string literal after deployment it is giving an error saying "ORA-00920: invalid relational operator".
    can any one throw some input on this .
    Thanks in Advance
    Srikanth

    You will see this error if the search condition was entered with an invalid or missing relational operator.
    You need to include a valid relational operator such as
      =, !=, ^=, <>, >, <, >=, <=, ALL, ANY, [NOT] BETWEEN, EXISTS, [NOT] IN, IS [NOT] NULL, or [NOT] LIKE in the condition. in the sql statement.
    Can you throw some more light on how are you designing your project?

  • Problem with Select statement.

    DATA: wa_usr05   TYPE usr05.
    The select statement always gives sy-subrc = 0
    even if there is no entry with parid = 'ZRD'.
    On successful it fills the structure wa_usr05 as
    MANDT     C     3      ACC
    BNAME     C     12      SCL
    PARID     C     20      X
    PARVA     C     18
    but mandt is 310.
    USR05 is a pool table and has mandt field.
            SELECT SINGLE bname
                          parid
                          parva
                FROM usr05
                INTO wa_usr05
                WHERE bname = sy-uname AND
                      parid = 'ZRD'    AND
                      parva = 'x'  OR  parva = 'X'.
    Let me know the reason and solution to the problem.

    SELECT SINGLE * FROM usr05
    INTO wa_usr05
    WHERE bname = sy-uname AND
    parid = 'ZRD' AND
    parva = <b>'X'</b> .
    Use single * as u have defined the wa+usr05 as usr05.
    Else.
    DATA: i_usr05 TYPE STANDARD TABLE of usr05.
    SELECT * FROM USR05
             INTO TABLE usr05
             WHERE bname = sy-uname AND
             parid = 'ZRD' AND
            parva = <b>'X'</b> .
    Then loop at itab and write data.
    Hope this solves ur query.
    Reward points if this helps.
    Message was edited by:
            Judith Jessie Selvi

  • Facing problem in select statement dump DBIF_RSQL_INVALID_RSQL CX_SY_OPEN_S

    Hi Experts,
    I  am facing the problem in the select statement where it giving the short dump
    DBIF_RSQL_INVALID_RSQL CX_SY_OPEN_S.
    i have searched many forms, but i found that the select option s_matnr have the limitaion 2000 entreis, but i am passing same s_matnr to other select statement with more than 2000 entries but it is not giving me any short dump.
    but i am facing problem with only one select statement where if i  pass select option s_matnr more than 1500 entris also giving short dump.
    my select statement is
    SELECT * FROM bsim                                       
             INTO CORRESPONDING FIELDS OF TABLE g_t_bsim_lean  
               FOR ALL ENTRIES IN t_bwkey   WHERE  bwkey = t_bwkey-bwkey
                                            AND    matnr IN matnr
                                            AND    bwtar IN bwtar
                                            AND    budat >= datum-low.
    in the internal table g_t_bsim_lean internal table contain all the fields of the table bsim with 2 fields from other table.
    Please let me know whether i need to change the select statement or any other solution for this.
    Regards,
    udupi

    my select query is like this:
    DATA: BEGIN OF t_bwkey OCCURS 0,                          "184465
              bwkey LIKE bsim-bwkey,                            "184465
            END OF t_bwkey.                                     "184465
      LOOP AT g_t_organ          WHERE  keytype  =  c_bwkey.
        MOVE g_t_organ-bwkey     TO  t_bwkey-bwkey.
        COLLECT t_bwkey.                                        "184465
      ENDLOOP.                                                  "184465
      READ TABLE t_bwkey INDEX 1.                               "184465
      CHECK sy-subrc = 0.                                       "184465
      SELECT * FROM bsim                                        "n443935
             INTO CORRESPONDING FIELDS OF TABLE g_t_bsim_lean   "n443935
               FOR ALL ENTRIES IN t_bwkey   WHERE  bwkey = t_bwkey-bwkey
                                            AND    matnr IN matnr
                                            AND    bwtar IN bwtar
                                            AND    budat >= datum-low.

  • Problem with SELECT statement. What is wrong with it?

    Why is this query....
    <cfquery datasource="manna_premier" name="kit_report">
    SELECT Orders.ID,
           SaleDate,
           Orders.UserID,
        Distributor,
        DealerID,
        Variable,
        TerritoryManager,
        US_Dealers.ID,
           DealerName,
        DealerAddress,
        DealerCity,
        DealerState,
        DealerZIPCode,
        (SELECT SUM(Quantity)
         FROM ProductOrders PO
         WHERE PO.OrderID = Orders.ID) as totalProducts,    
    FROM Orders, US_Dealers
    WHERE US_Dealers.ID = DealerID AND SaleDate BETWEEN #CreateODBCDate(FORM.Start)# AND #CreateODBCDate(FORM.End)# AND Variable = '#Variable#'
    </cfquery>
    giving me this error message...
    Error Executing Database Query.
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
    The error occurred in D:\Inetpub\mannapremier\kit_report2.cfm: line 20
    18 :              WHERE PO.OrderID = Orders.ID) as totalProducts,        
    19 : FROM Orders, US_Dealers
    20 : WHERE US_Dealers.ID = DealerID AND SaleDate BETWEEN #CreateODBCDate(FORM.Start)# AND #CreateODBCDate(FORM.End)# AND Variable = '#Variable#'
    21 : </cfquery>
    22 :
    SQLSTATE
      42000
    SQL
       SELECT Orders.ID, SaleDate, Orders.UserID, Distributor, DealerID, Variable, TerritoryManager, US_Dealers.ID, DealerName, DealerAddress, DealerCity, DealerState, DealerZIPCode, (SELECT SUM(Quantity) FROM ProductOrders PO WHERE PO.OrderID = Orders.ID) as totalProducts, FROM Orders, US_Dealers WHERE US_Dealers.ID = DealerID AND SaleDate BETWEEN {d '2009-10-01'} AND {d '2009-10-31'} AND Variable = 'Chick Days pre-book'
    VENDORERRORCODE
      -3504
    DATASOURCE
      manna_premier
    Resources:
    I copied it from a different template where it works without error...
    <cfquery name="qZVPData" datasource="manna_premier">
    SELECT UserID,
           TMName,
        UserZone,
              (SELECT COUNT(*)
               FROM Sales_Calls
               WHERE Sales_Calls.UserID = u.UserID) as totalCalls,
        (SELECT COUNT(*)
         FROM Orders
         WHERE Orders.UserID = u.UserID) as totalOrders,
        (SELECT SUM(Quantity)
         FROM ProductOrders PO
         WHERE PO.UserID = u.UserID AND PO.NewExisting = 1) as newItems,
        (SELECT SUM(NewExisting)
         FROM  ProductOrders PO_
         WHERE PO_.UserID = u.UserID) as totalNew,
        SUM(totalOrders)/(totalCalls) AS closePerc
    FROM Users u
    WHERE UserZone = 'Central'
    GROUP BY UserZone, UserID, TMName
    </cfquery>
    What is the problem?

    It's hard to say: what's your request timeout set to?
    700-odd records is not much of a fetch for a decent DB, and I would not expect that to case the problem.  But then you're using Access which doesn't fit the description of "decent DB" (or "fit for purpose" or "intended for purpose"), so I guess all bets are off one that one.  If this query is slow when ONE request is asking for it, what is going to happen when it goes live and multiple requests are asking for it, along with all the other queries your site will want to run?  Access is not designed for this.  It will really struggle, and cause your site to run like a dog.  One that died serveral weeks ago.
    What else is on the template?  I presume you're doing something with the query once you fetch it, so could it be that code that's running slowly?  Have you taken any steps to isolate which part of the code is taking so long?
    How does the query perform if you take the subquery out of the select line?  Is there any other way of getting that data?  What subquery will be running once for every row of the result set... not very nice.
    Adam

  • Having Problem in select statement.

    Dear gurus
    im having an issue in select statement.
    i have written a select statement which is fetching the result as i required but it takes to much time to execute.
    how to make it work fast.
    SELECT vbak~vkbur vbap~vbeln vbap~posnr vbak~audat
             vbap~kwmeng vbap~meins vbak~kunnr vbak~vkorg
             vbak~vtweg  vbak~spart matnr matkl auart
             vbap~abgru
      INTO CORRESPONDING FIELDS OF TABLE so_tab
      FROM vbak
      JOIN vbap ON vbak~vbeln = vbap~vbeln
      WHERE audat IN in_date
      AND matnr IN matnr
      AND ( auart = 'ZISO' OR auart = 'ZEXP' )
      AND vbap~werks IN werks  .
      SELECT lips~vbeln lips~posnr likp~lfdat lips~lfimg
             lips~meins likp~kunag matnr vgbel vgpos
             lfart
      INTO CORRESPONDING FIELDS OF TABLE del_tab
      FROM likp
      JOIN lips ON likp~vbeln = lips~vbeln
      FOR ALL entries IN so_tab
      WHERE vgbel = so_tab-vbeln
      AND vgpos = so_tab-posnr
      AND lfdat IN in_date
      AND likp~werks IN werks.
    Regards
    Saad Nisar.

    Hi,
    I agree with sabu.
    Along with these you need to do following things -
    SELECT vbak~vkbur vbap~vbeln vbap~posnr vbak~audat
             vbap~kwmeng vbap~meins vbak~kunnr vbak~vkorg
             vbak~vtweg  vbak~spart matnr matkl auart
             vbap~abgru
      INTO CORRESPONDING FIELDS OF TABLE so_tab
      FROM vbak
      JOIN vbap ON vbak~vbeln = vbap~vbeln
      WHERE audat IN in_date
      AND matnr IN matnr
      AND ( auart = 'ZISO' OR auart = 'ZEXP' )
      AND vbap~werks IN werks  .
    {color:green}
    *if sy-subrc eq 0.*
    *so_tab_tmp[]  = so_tab[].*
    *sort so_tab_tmp by vbeln posnr.*
    *delete adjacent duplicates from so_tab_tmp by vbeln posnr.*
    *if so_tab_tmp[] is not initial.*
    {color:green}
      SELECT lips~vbeln lips~posnr likp~lfdat lips~lfimg
             lips~meins likp~kunag matnr vgbel vgpos
             lfart
      INTO CORRESPONDING FIELDS OF TABLE del_tab
      FROM likp
      JOIN lips ON likp~vbeln = lips~vbeln
      FOR ALL entries IN so_tab_tmp
      WHERE vgbel = so_tab_tmp-vbeln
      AND vgpos = so_tab_tmp-posnr
      AND lfdat IN in_date
      AND likp~werks IN werks.
    {color:green}
    *endif.*
    *endif.*
    {color:green}

  • Problem executing SELECT statement due to st_spatial column type

    I am using a CachedRowSet and cache.execute() will not run because it does not support the st_spatial column type. I have been told to use the column metadata to build a select statement of column names, and check the column's type before you add it to the select clause. But, I am unsure of what to do since I can't get column names without running a select statement first... I will attach some code for you to look at, but please give me suggestions!
    try{
    Class.forName("com.informix.jdbc.IfxDriver");
    CachedRowSet cache = new CachedRowSet();
    cache.setReadOnly(true);
    cache.setUrl(dbname);
    cache.setUsername(user);
    cache.setPassword(password);
    cache.setCommand("SELECT * FROM "+table);
    try{
    cache.execute();
    }catch(Exception e){
    out.print("Can't Display");
    OTHER JSP CODE THAT WORKS WITH THE RESULTS FROM ABOVE
    }catch(Exception exc){
    out.println(exc.toString());
    } // end try-catch

    I honestly don't have a clue. I have no idea what the st_spatial data type is, or where it is defined, and as a result, I don't know why Java would be complaining about it. I do know that java.sql.ResultSet doesn't care about it (it would internally recognize it as a plain old object type via the getObject() method and you would have to cast it to st_spatial).
    What I would check:
    Is the Informix driver up to date?
    Does the CachedRowSet class extend ResultSet or otherwise use it as an internal data structure? If so, does it properly create the ResultSetMetaData object and no exceptions are being trapped?
    Otherwise... when copying data from the ResultSet object into its own internal data structure, does it correctly realize that the st_spatial column should NOT be copied into a String or a slot in a String array?
    Does a quick and dirty command line version of your program properly use CachedRowSet to retrieve at least one record from your database?
    Basically, put the JSP aside and just test the CachedRowSet to make sure it is working correctly. I have no idea what's in that class since it is not a Java standard class, so I can't really give you any additional suggestions.

  • Conditional Columns in Select Statement for any type of Report

    Okay so I had a requirement to conditionally show columns on a report when the data in the column was not null. I played around the "vertical" report mentioned in other posts but it didn't work well for my needs. Also I know that there is a javascript solution for this as demonstarted in Denes Kubicek's app (which was copied from Vikas :) ). Anyways listed below is my approach.... Hope this can help anyone else out as it's just pl/sql returning sql. Also you will need execute on dbms_sql for this to work.
    declare
    v_count number := 0;
    v_row_count number := 0;
    v_col_name varchar2(100);
    q varchar2(4000) := 'select ';
    v_table_name varchar2(100) := :SOME_TABLE_NAME;
    v_id varchar2(100) := 'num = '||:SOME_APEX_VALUE;
    my_c INTEGER;
    fdbk INTEGER;
    statement varchar2(2000);
    cval_out varchar2(2000);
    nval_out number;
    begin
    select count(*) into v_count from cols
    where table_name = v_table_name;
    for counter in 1..v_count
    loop
    select column_name into v_col_name
    from cols where table_name = v_table_name
    and counter = column_id;
    statement := 'select count(*) '||
    ' from '||v_table_name||
    ' where '||v_col_name||' is not null and '||v_id;
    my_c := dbms_sql.open_cursor;
    dbms_sql.parse(my_c,statement,dbms_sql.native);
    dbms_sql.define_column(my_c,1,nval_out);
    fdbk := dbms_sql.execute(my_c);
    LOOP
    exit when dbms_sql.fetch_rows(my_c) = 0;
    dbms_sql.column_value(my_c,1,nval_out);
    end loop;
    v_row_count := nval_out;
    dbms_sql.close_cursor(my_c);
    if v_row_count > 0 then
    q:=q||v_col_name||',';
    end if;
    end loop;
    if(substr(q,length(q),1) = ',') then
    q:= substr(q,0,length(q)-1);
    end if;
    q:= q||' from '||v_table_name||' where '||v_id;
    end;Hope this helps...
    -David
    Message was edited by:
    rdpatric

    Hi Gints,
    Thank you for your reply. This is my query and
    nvl(TICKET_JOIN.TDQRLV,0) ACC_SHIPPED_QTY,
    TICKET_JOIN.TDSOQS QUANTITY_TICKETED are the columns tha's creating issue. If I comment those columns Index is accessed properly.
    select
    'TKT' SOURCE,
    TICKET_JOIN.TKDO01 HIRE_ID,
    TICKET_JOIN.TKQ101 TRUCK_ID,
    TICKET_JOIN.TKVEHT TRUCK_TYPE,
    1 TRUCK_COMM,
    nvl(TKCMP1,0) TICKET_NUM,
    nvl(TKADTM,0) TICKET_TIME,
    --TICKET_JOIN.TDSOQS QUANTITY_TICKETED,
    0 CHECKIN_TIME,
    --nvl(TICKET_JOIN.TDQRLV,0) ACC_SHIPPED_QTY,
    nvl(DDADTM,0) START_TIME
    from
    (select
    TICKET.TKCMP1,
    TICKET.TKDO01,
    TICKET.TKQ101,
    TICKET.TKADTM ,
    TICKET.TKVEHT,
    TICKET_DETAILS.TDAITM ,
    TICKET_DETAILS.TDQRLV ,
    TICKET_DETAILS.TDSOQS ,
    TICKET.TKCNTF,
    TICKET.TKTRDJ,
    TICKET.TK58GA8
    from
    CRPDTA.F5800091 TICKET_DETAILS ,
    CRPDTA.F5800090 TICKET
    where TICKET.TKCMP1 = TICKET_DETAILS.TDCMP1
    and TICKET.TKTRDJ = TICKET_DETAILS.TDTRDJ
    and TICKET.TKTRDJ = 107085
    and TICKET.TKEV12 <> 'Y'
    and TICKET.TK58GA8='ECSEO'
    and TICKET.TKCNTF = '11') TICKET_JOIN ,
    (select
    DDDOCO,
    DDCNTF,
    DDQTFN,
    DDAITM,
    DDADTM,
    DD58GA8,
    DDTRDJ
    from
    CRPDTA.F5800051 ORDER_DETAILS,
    CRPDTA.F5800050 ORDER_HEADER
    where
    ORDER_HEADER.DHDOCO = ORDER_DETAILS.DDDOCO
    and ORDER_HEADER.DHTRDJ = ORDER_DETAILS.DDTRDJ
    and ORDER_HEADER.DH58GA8 = ORDER_DETAILS.DD58GA8
    and ORDER_HEADER.DHDCTO = ORDER_DETAILS.DDDCTO
    /*and
    (ORDER_HEADER.DHTRDJ = 107085
    OR (ORDER_HEADER.DHTRDJ = 107084 and ORDER_HEADER.DHEV04='Y')
    and TRIM(ORDER_HEADER.DH58GA8) = 'ECSEO'
    and TRIM(ORDER_DETAILS.DDCNTF) = '11' ) ORDER_VIEW
    where TICKET_JOIN.TKTRDJ = ORDER_VIEW.DDTRDJ
    and TICKET_JOIN.TDAITM = ORDER_VIEW.DDAITM
    and TICKET_JOIN.TKCNTF = ORDER_VIEW.DDCNTF
    and TICKET_JOIN.TK58GA8 = ORDER_VIEW.DD58GA8
    and NOT EXISTS ( select 1 from CRPDTA.F5800120 TRUCK_ASSIGNMENT
    where TATRDJ = 107085
    and TACNTF = '11'
    and TA58GA8 = 'ECSEO'
    and TICKET_JOIN.TKQ101||TICKET_JOIN.TKVEHT = TAQ101||TAVEHT )
    Thanks
    GM

  • Problems with select statement

    Hi,
    For some reason I cannot find the solution for the following problem.
    I have an internal table.
    Now I like to make an select over a database table, while only rows should be selected, where the key field occurs in the internal table and in case of  identical key field only the row with the lowest value in another column is selcted.
    Example:
    - internal table:
    col1  col2  col3
    1     A     AA
    2     B     AA
    3     A     AC
    -database table:
    col1  col2  col3
    1     001   CD
    1     002   CF
    1     003   CG
    2     001   CD
    2     002   CF
    2     003   CG
    3     002   CF
    3     003   CG
    4     001   CD
    4     002   CF
    4     003   CG
    - the selected database entries should be
    1     001   CD
    2     001   CD
    3     002   CF
    explication:
    - entries with 4 in the first column do not occur in the internal table, so they do not appear in the selection
    - in case of more than one entry in the database table only the one with the lowest value in column two will be selected
    If you have any idea how this could be solved, I would really appreciate you help.
    regards
    Torsten

    Hi,
    1) u have to select based on internal table 1
    2) u have to filter the internal table 2 for minimum value.
    select col1 col2 col3
    from <any table>
    into table <Internal_table_final>
    for all entries in <Internal_table_1>
    where col1 = Internal_table_1-col1.
    sort Internal_table_final by col1 col2.
    loop at Internal_table_final.
       at new col1.
          continue.
       endat.   
       delete Internal_table_final.
    endloop.
    <b>try this</b>
    Regards
    <b>Mark Helpful Answers</b>
    Message was edited by: Manoj Gupta

Maybe you are looking for