Syntax Error in SELECT statement

Hi,
My ABAP statement is:
select b1~fa a1~fb
INTO CORRESPONDING FIELDS OF TABLE it_1
from (table_nm) as a1 inner join db_tab2 as b1
on a1~fb = b1~fb.
For this statement it gives me following error in syntax check:
*Wrong expression "INNER" in FROM clause. WHERE condition.     *     
Thanks,
CD

Hi
Try something like this:
DATA: BEGIN OF ITAB OCCURS 0,
        A,
        B,
      END   OF ITAB.
DATA: TABLENAME(30).
DATA: WA_FTAB(72) TYPE C,
      FTAB        LIKE TABLE OF WA_FTAB.
WA_FTAB = 'A'.   APPEND WA_FTAB TO FTAB.
SELECT (FTAB) FROM (TABLENAME) INTO TABLE ITAB.
LOOP AT ITAB.
  SELECT SINGLE A FRO <TABLE 2>
    INTO ITAB-B
    WHERE A = ITAB-A.
  MODIFY ITAB.
ENDLOOP.
See this sample:
DATA: BEGIN OF ITAB OCCURS 0,
        VBELN LIKE VBAK-VBELN,
        POSNR LIKE VBAP-POSNR,
        VKORG LIKE VBAK-VKORG,
      END   OF ITAB.
DATA: TABLENAME(30) VALUE 'VBAP'.
DATA: WA_FTAB(72) TYPE C,
      FTAB        LIKE TABLE OF WA_FTAB.
WA_FTAB = 'VBELN'.   APPEND WA_FTAB TO FTAB.
WA_FTAB = 'POSNR'.   APPEND WA_FTAB TO FTAB.
SELECT (FTAB) UP TO 10 ROWS FROM (TABLENAME) INTO TABLE ITAB.
LOOP AT ITAB.
  SELECT SINGLE VKORG FROM VBAK INTO ITAB-VKORG
    WHERE VBELN = ITAB-VBELN.
  MODIFY ITAB.
ENDLOOP.

Similar Messages

  • [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.

    Hi,
    I am getting following error message ,
    [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.
    When run this code.
    <%@ page import= "java.sql.*"%>
    <%
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:bspipdb");
    Statement st = con.createStatement();
    st.executeUpdate("update tscipshift set 11-Aug-08='M' where TechN='Elamparuthi'");
    %>
    tscipshift=table ,column=11-Aug-08 are all exist.
    I dont know why I am getting error mesage.
    Any idea why?

    Shahbaz2008 wrote:
    you haven't set your user name and password hereI don't believe that's necessary with Access. Then again, it's not an enterprise database.
    Connection con = DriverManager.getConnection("jdbc:odbc:bspipdb");
    change it to this
    Connection con = DriverManager.getConnection("jdbc:odbc:bspipdb","+username+","+password+");
    here pass your username and password...
    In Oracle default user name and password is
    username = scott
    password = tigerSo who uses that? Only an eejit would leave that account open.
    So the statement would be
    Connection con = DriverManager.getConnection("jdbc:odbc:bspipdb","scott","tiger");
    or In Mirosoft Access there is no user name and password so the statement will be Like I said - unnecessary, and not the reason the OP is having problems.
    Connection con = DriverManager.getConnection("jdbc:odbc:bspipdb","","");>
    Besides this change your table name 11-Aug-08 to anything that is not start with number or any special symbols.
    for example aug112008 is good or aug is too good.No, it's still not good if you understand ANYTHING about relational databases and normalization.
    I think it would work.I think you're just as stup!d as the OP.
    %

  • JDBC: Syntax error in UPDATE statement???

    Hi,
    I have been trying to solve this seemingly simple problem for the past 4 hours, and I had no success. I am working on a jdbc:odbc connection which utilizes MS Access. I have been constantly getting "Syntax error in UPDATE statement", and this is the statement
    (name of the table is CDs, columns are number, artist, album, label and date - all strings):
    query = "UPDATE CDs SET artist = '" + fields.artist.getText() +"', album = '" +
    fields.album.getText() + "', label = '" +
    fields.label.getText() + "', date = '" +
    fields.date.getText() + "' WHERE number = '" + fields.number.getText() + "'";
    Can anybody recognize an error? Thank you,
    mirkokrug

    A couple of possibilities.
    If the column NUMBER is numeric then it wouldn't need quotes around the data value. Also if the column DATE is a date or date/time type then the format from the textbox may not be correct.
    Col

  • Syntax error in modify statement

    Hi Friends,
    There is an Internal table IT_STATUS which is the Parameter in BADI Method IF_EX_WORKORDER_UPDATE~BEFORE_UPDATE.
    Below is the code i have written
    Data:  wa_status type cobai_s_status,
                       stat TYPE TABLE OF jstat,
                       wa_stat type jstat.
          CALL FUNCTION 'STATUS_READ'
            EXPORTING
             client                 = sy-mandt
              objnr                  = gv_objnr
    *     ONLY_ACTIVE            = ' '
    *   IMPORTING
    *     OBTYP                  =
    *     STSMA                  =
    *     STONR                  =
           TABLES
             status                 = stat
           EXCEPTIONS
             object_not_found       = 1
             OTHERS                 = 2
          IF sy-subrc <> 0.
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          ELSE.
           loop at it_status into wa_status.
            read table stat into wa_stat with key STAT = wa_status-stat.
            if sy-subrc = 0.
             wa_status-stat = wa_stat-stat.
             wa_status-INACT = wa_stat-INACT.
             modify it_status from wa_status transporting stat inact.
            endif.
           endloop.
          ENDIF.
    At Modify statement it is giving a syntax error 'The <b>field "IT_STATUS" cannot be changed.-</b>'. what could be the reason?
    Please provide me the solution.
    Thanks & Regards,
    Satish

    Hi Rob,
    This is the whole code which i had written in method
    METHOD if_ex_workorder_update~before_update.
      DATA: gv_aufnr TYPE afih-aufnr,
            gv_objnr TYPE jest-objnr,
            stat TYPE TABLE OF jstat,
            wa_stat TYPE jstat,
            wa_header TYPE cobai_s_header,
            wa_status TYPE cobai_s_status,
            it_status_new TYPE cobai_t_status.
      DATA: status_index TYPE sy-tabix.
      BREAK-POINT.
      LOOP AT it_header INTO wa_header.
        SELECT SINGLE aufnr FROM afih INTO gv_aufnr WHERE warpl = wa_header-warpl AND abnum = 1.
        IF sy-subrc = 0.
          CONCATENATE 'OR' gv_aufnr INTO gv_objnr.
          CALL FUNCTION 'STATUS_READ'
            EXPORTING
             client                 = sy-mandt
              objnr                  = gv_objnr
    *     ONLY_ACTIVE            = ' '
    *   IMPORTING
    *     OBTYP                  =
    *     STSMA                  =
    *     STONR                  =
           TABLES
             status                 = stat
           EXCEPTIONS
             object_not_found       = 1
             OTHERS                 = 2
          IF sy-subrc <> 0.
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          ELSE.
            LOOP AT it_status INTO wa_status.
              status_index = sy-tabix.
              READ TABLE stat INTO wa_stat WITH KEY stat = wa_status-stat.
              IF sy-subrc = 0.
                wa_status-stat = wa_stat-stat.
                wa_status-inact = wa_stat-inact.
                MODIFY it_status INDEX status_index FROM wa_status TRANSPORTING stat inact.
              ENDIF.
            ENDLOOP.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDMETHOD.
    Hope it will get resolved
    Regards,
    Satish

  • Unsure of syntax for SQL SELECT statement, please help

    I am trying to execute the following SQL statement:
    ResultSet rs = stB.executeQuery("SELECT quantity FROM stocklevels WHERE code=salesCode[x]");where SalesCode is an integer array and x is a counter used to loop this part of the code. I keep getting the "syntax error - missing operator" message when I run the code and get to this line, can anybody please tell me the correct syntax/form to use? Many thanks.

    Is salesCode an array in Java or in your DB? I don't know anything about SQL arrays, so I'll assume it's in your Java code.
    You want to put the value of salesCode[x] into the query--say 123456. But what you've got is like doing System.out.println("The code = salesCode[x]"); and then wondering why you're seeing "salesCode[x]" instead of "123456. You'd need to do System.out.println("The code = " + salesCode[x]); Similarly, you could take the "salesCode[x]" out of the string literal that's forming the query, in order to have it evaluated as an int and stuffed into the string as "123456". It would be better to use a PreparedStatement though: ps = con.prepareStatement("select .... where code = ?");
    ps.setInt(1, salsedCode[x]);
    rs = ps.executeQuery();

  • Runtime error for SELECT statement

    Hi All,
    I have written a SELECT statement as follows in my code.
    select budat pernr aufnr vornr from AFRU
    into corresponding fields of table it_vornr
    for all entries in it_cats_tmp
    where budat = it_cats_tmp-workdate
    and pernr = it_cats_tmp-pernr
    and aufnr = it_cats_tmp-rnplnr.
    The table IT-CATS_TMP is having around 3000+ lines.
    When control moves to this statement, the system is throwing Runtime error or its taking around 30 minutes time to execute.
    If i query the same table (AFRU) in SE11 for the same set of conditions, the table displays relevent data immediately.
    What might be the reason for this delay/Runtime Error?
    Shall i need to change the syntax for better performance?
    Your guidelines are highly appreciated......
    Regards
    Pavan

    Hi
    1. Try to put WHERE conditions for KEY FIELDS.
    Solution: Create a RANGE for the key fields & put that in SELECT Query.
    DATA: gr_rueck TYPE RANGES OF afru-rueck.
    SELECT .. WHERE rueck IN gr_rueck.
    2. Avoid using CORRESPONDING FIELDS OF TABLE in SELECT.
    Solution: Change internal table fields ORDER.
    TYPES:
    BEGIN OF TY_VORNR,
      budat TYPE ..
      pernr TYPE ..
      aufnr TYPE ..
      vornr TYPE ..
      ... " Other fields
    END OF TY_VORNR.
    SELECT .. INTO TABLE IT_VORNR ...

  • Syntax Error with EXPORT statement in ECC 6

    Hi All,
    I have one issue with EXPORT statement syntax.
    I have declared data like below:
    DATA: BEGIN OF mem_id,
              mandt LIKE sy-mandt,
              uname LIKE sy-uname,
              modno LIKE sy-modno,
            END OF mem_id.
    export the memory id
        EXPORT E_VBKOK XANZPK TEXTTAB XBOLNR TO MEMORY ID MEM_ID.
    When I am checking the syntax error i am getting like "MEM_ID" must be a character-type field (data type C, N, D or T). by "INTERFACE". by "INTERFACE". "INTERFACE". by "INTERFACE". by "INTERFACE".
    I know this statement would be like IMPORT ITAB TO JTAB FROM MEMORY ID 'table'. So I have written like below
    EXPORT E_VBKOK XANZPK TEXTTAB XBOLNR TO MEMORY ID 'MEM_ID'. But still it is throwing an error.
    Can you please let me know how can I resolve this?
    Regards,
    Jyothi CH.

    Hi Jyothi,
    data: l_var type string.
    concatenate '6' '8' into l_var separated by space.
    export l_var to memory id 'BB'.
    Here we have to declare the type(structure) for l_var not for BB
    and in another program
    data:l_var type string.
    import l_var from memory id 'BB'.
    write : l_var.

  • Runtime error at select statement in RFC_READ TABLE FM

    Dear All,
       I have copied the standard FM RFC_READ_TABLE to incorporate the customer needs. Below is the select query which I have written in this FM.
    SELECT (po_search_text-column_text) INTO <wa> FROM ekko
          INNER JOIN ekpo ON ekko~ebeln = ekpo~ebeln
          INNER JOIN eket ON ekpo~ebeln = eket~ebeln AND ekpo~ebelp = eket~ebelp
          INNER JOIN lfa1 ON ekko~lifnr = lfa1~lifnr
          INNER JOIN lfm1 ON ekko~lifnr = lfm1~lifnr AND ekko~ekorg = lfm1~ekorg
          INNER JOIN lfb1 ON ekko~lifnr = lfb1~lifnr AND ekko~bukrs = lfb1~bukrs
          INNER JOIN t024 ON ekko~ekgrp = t024~ekgrp
          INNER JOIN zatscsng_status ON eket~ebeln = zatscsng_status~po_number
          AND   eket~ebelp = zatscsng_status~po_line
          AND   eket~etenr = zatscsng_status~po_sched_line
          INNER JOIN adrc ON zatscsng_status~delivery_addr = adrc~addrnumber
          WHERE (po_search_text-cond_text)
          ORDER BY (po_search_text-sort_text).
    Here, posearch_text-column_text_ will have the fields to be selected at runtime and posearch_text-cond_text_ is the where condition. It is running fine in this case.
    But when I try to select Item Category ( EKPO-PSTYP), if data is present for this category, it is returning the values but if data is not there for the particular item category in the where clause, it is giving a RUNTIME ERROR at the select statement.
    Here is the ERROR ANALYSIS:
    An exception occurred that is explained in detail below.
    The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was
      not caught in
    procedure "ZATSCSNG_RFC_READ_TABLE" "(FUNCTION)", nor was it propagated by a
      RAISING clause.
    Since the caller of the procedure could not have anticipated that the
    exception would occur, the current program is terminated.
    The reason for the exception is:
    The current ABAP program has tried to execute an Open SQL statement
    which contains a WHERE, ON or HAVING condition with a dynamic part.
    The part of the WHERE, ON or HAVING condition specified at runtime in
    a field or an internal table, contains the invalid value "<L_LINE>-PSTYP".
    Edited by: Rob Burbank on Mar 17, 2010 5:09 PM

    Now that's what I call a join statement...
    You probably have a bug in how you build po_search_text-cond_text, the content must be a syntactically correct where clause. It seems that in your example there is just "<L_LINE>-PSTYP" without a condition, so try omitting it altogether.
    Debug the content of po_search_text-cond_text before it hits the select statement.
    Thomas

  • Error in select statement in CMOD

    Hi Friends
    I am enhancing a data source with some fields and in the CMOD i am writing the code.
    My delcaration is as follows
    begin of  ty_dfkkzp,
                    SELW2       type  dfkkzp-SELW2,
                    BLART       type  dfkkzp-BLART ,
                    BUDAT       type  dfkkzp-BUDAT ,
                    BLDAT       type  dfkkzp-BLDAT ,
                    TBETR       type  dfkkzp-TBETR  ,
                    ZZRECEIPT   type  dfkkzp-ZZRECEIPT ,
                    ZZPAYCAT  type  dfkkzp-ZZPAYCAT ,
                    ZZPAYSRC  type  dfkkzp-ZZPAYSRC ,
                    ZZPAYTYPE   type  dfkkzp-ZZPAYTYPE ,
                    ZZTENDER  type  dfkkzp-ZZTENDER ,
                end of  ty_dfkkzp.
    Following is my SELECT statement.
    select
            SELW2
            BLART
            BUDAT
            BLDAT
            TBETR
            ZZRECEIPT
            ZZPAYCAT
            ZZPAYSRC
            ZZPAYTYPE
            ZZTENDER
            into corresponding fields of table lt_dfkkzp
            from dfkkzp
            for all entries in it_data
           where SELW2 = it_data-VTREF.
    I am getting an error in the where clause. This is becuase VTERF ( Contract) is of type CHAR and length 20, where as SELW2 is of type CHAR but Length 35. I know the length and type should be the same. But this table DFKKZP strangely has SELW2(Contract) has length 35.
    Can someone please suggest me how to handle this inorder for me to get this correct?.
    Thanks in adv.
    Regards
    BN

    Hi,
    try this and let me know if it works.
    Declare another internal table and work area like it_data1 type it_data as shown below.
    Begin of it_data1_wa,
    ......... type........,
    ......... type .......,
    SELW2 type dfkkzp-SELW2,
    end if it_data_wa1.
    data: it_data1 like standard table of it_data_wa.
    data: it_data_wa type it_data
    include all the fields inside the table.
    loop at it_data into it_data_wa.
    move corresponding lt_data_wa to it_data1_wa.
    it_data1_wa-SELW2 = it_data_wa-VTREF.
    append it_data1_wa to it_data1.
    end loop.
    now write the same select statement for all entries in it_data1 instead of it_data.
    Regards,
    Anusha

  • Syntax Error in Update Statement

    Would a smart and kind CF pro mind putting a fresh pair of
    eyes on this code and tell me where the syntax error is? All the
    fields in the statement are numeric except the last one (comments).
    I have enclosed them in val() to ensure they are numeric when
    inserted into the DB. The fields they're being inserted into are
    numeric. I need to be numeric because I will be doing calculations
    on them. Also, I have triple-checked to ensure the datasource,
    table, and field names all match.
    Thanks,
    GwenH

    Try using <cfqueryparam>
    <cfquery datasource="reviews">
    UPDATE evals
    SET focus = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.focus#">
    , strengths = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.strengths#">
    , tailored = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.tailored#">
    , badinfo = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.badinfo#">
    , format = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.format#">
    , visual = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.visual#">
    , grammar = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.grammar#">
    , pronouns = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.pronouns#">
    , written = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.written#">
    , achieve = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.achieve#">
    , sell = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.sell#">
    , negative = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.negative#">
    , top = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.top#">
    , general = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.general#">
    , intro = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.intro#">
    , orientation = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.orientation#">
    , paragraphs = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.paragraphs#">
    , two = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.two#">
    , length = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.length#">
    , none = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.none#">
    , comments = <cfqueryparam cfsqltype="cf_sql_clob"
    value="#form.comments#">
    WHERE resumeID = <cfqueryparam cfsqltype="cf_sql_numeric"
    value="#form.resumeID#">
    </cfquery>
    Ken Ford
    Adobe Community Expert Dreamweaver/ColdFusion
    Adobe Certified Expert - Dreamweaver CS3
    Adobe Certified Expert - ColdFusion 8
    Fordwebs, LLC
    http://www.fordwebs.com
    "GwenH" <[email protected]> wrote in message
    news:[email protected]...
    > Would a smart and kind CF pro mind putting a fresh pair
    of eyes on this
    > code
    > and tell me where the syntax error is? All the fields in
    the statement are
    > numeric except the last one (comments). I have enclosed
    them in val() to
    > ensure
    > they are numeric when inserted into the DB. The fields
    they're being
    > inserted
    > into are numeric. I need to be numeric because I will be
    doing
    > calculations on
    > them. Also, I have triple-checked to ensure the
    datasource, table, and
    > field
    > names all match.
    >
    > Thanks,
    > GwenH
    >
    > <cfquery datasource="reviews">
    > UPDATE evals
    > SET
    > focus = val(#form.focus#)
    > , strengths = val(#form.strengths#)
    > , tailored = val(#form.tailored#)
    > , badinfo = val(#form.badinfo#)
    > , format = val(#form.format#)
    > , visual = val(#form.visual#)
    > , grammar = val(#form.grammar#)
    > , pronouns = val(#form.pronouns#)
    > , written = val(#form.written#)
    > , achieve = val(#form.achieve#)
    > , sell = val(#form.sell#)
    > , negative = val(#form.negative#)
    > , top = val(#form.top#)
    > , general = val(#form.general#)
    > , intro = val(#form.intro#)
    > , orientation = val(#form.orientation#)
    > , paragraphs = val(#form.paragraphs#)
    > , two = val(#form.two#)
    > , length = val(#form.length#)
    > , none = val(#form.none#)
    > , comments = '#form.comments#'
    > WHERE resumeID = #form.resumeID#
    > </cfquery>
    >

  • Error in Select Statement " Comma Without Preceding Colon"

    Helo Gurus.
    This is my select query :
    SELECT SINGLE
           STREET
           HOUSE_NUM1
           CITY2
           TEL_NUMBER
           FAX_NUMBER
           POST_CODE1
           STR_SUPPL1
           REGION
           INTO ( L_STREET, L_HOUSENUM, L_CITY2, L_TELNUMBER , L_FAXNUMBER , L_POSTCODE1 , L_STRSUPPL1 , L_REGION )
           FROM ADRC    
           WHERE ADDRNUMBER = l_addrnumber.
    But i am getting error as " Comma Without Preceding Colon"
    How to correct this?
    Points are assured !!!

    Hi Anay Kulkarni ,
    find the modified code with out syntax error.....
    START-OF-SELECTION.     
    SELECT SINGLE STREET
                  HOUSE_NUM1
                  CITY2
                  TEL_NUMBER
                  FAX_NUMBER
                  POST_CODE1
                  STR_SUPPL1
                  REGION
               INTO (L_STREET, L_HOUSENUM, L_CITY2, L_TELNUMBER, L_FAXNUMBER, L_POSTCODE1, L_STRSUPPL1, L_REGION)
               FROM ADRC
    *           INTO (L_STREET, L_HOUSENUM, L_CITY2, L_TELNUMBER, L_FAXNUMBER, L_POSTCODE1, L_STRSUPPL1, L_REGION)
    WHERE ADDRNUMBER = '23453'.
    Dont forgot to Reward me points .....
    All the very best....
    Regards,
    Sreenivasa sarma K.

  • Syntax error in INSERT STATEMENT

    A problem on the date part of the query but why I don´t
    know, Thanks for any pointers,
    TIA
    <cfquery name="update1" datasource="trevor_SecurityDB">
    INSERT INTO imagesproducts
    (title, info, date)
    VALUES ( '#form.title#', '#form.info#', '#DateFormat(Now())#'
    </cfquery>
    Error Occurred While Processing Request
    Error Executing Database Query.
    [Macromedia][SequeLink JDBC Driver][ODBC
    Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error in
    INSERT INTO statement.
    The error occurred in uploadmember.cfm: line 28
    26 : INSERT INTO imagesproducts
    27 : (title, info, date)
    28 : VALUES ( '#form.title#', '#form.info#',
    '#DateFormat(Now())#' )
    29 : </cfquery>
    30 :
    SQL INSERT INTO imagesproducts (title, info, date) VALUES (
    'News test', 'Testing news info', '12-Jul-07' )
    DATASOURCE trevor_SecurityDB
    VENDORERRORCODE -3502
    SQLSTATE 42000

    Perhaps it is a reserved word issue with the date column,
    since
    date is an ODBC Reserved Keyword. You might try enclosing it
    within brackets [ ].
    <cfquery name="update1" datasource="trevor_SecurityDB">
    INSERT INTO imagesproducts
    (title, info, [date])
    VALUES ( '#form.title#', '#form.info#', '#DateFormat(Now())#'
    </cfquery>
    Or, if that doesn't help, you might try using a cfqueryparam
    tag for the '#DateFormat(Now())#' value using a cfsqltype =
    "CF_SQL_TIMESTAMP" (assuming a date/time datatype on the column).
    Also, you might look into using one of the CreateODBCDateTime() or
    CreateODBCDate() functions.
    Phil

  • Sql Error in Select statement when doing subquery

    Hi,
    I am trying to see what the error is in the subquery part of the select statement.
    Subquery should be fetching the safety_stock_quantity based on the MAX(effectivity_date).
    Any suggestions?
    SELECT kbn.last_update_date,itm.segment1,itm.description,kbn.kanban_card_number,kbn.kanban_size,
                   (SELECT msc.safety_stock_quantity
    FROM mtl_safety_stocks msc
    WHERE msc.effectivity_date = (select MAX(msc2.effectivity_date)
                   from mtl_safety_stocks msc2
                                            where msc2.inventory_item_id = itm.inventory_item_id
                                                 and msc2.organization_id = itm.organization_id)
                   AND msc.inventory_item_id = itm.inventory_item_id
         AND msc.organization_id = itm.organization_id                                        
    FROM mtl_system_items_b itm
    ,mtl_onhand_quantities_detail moqd
              ,mtl_safety_stocks msc
              ,mtl_kanban_card_activity kbn
    WHERE itm.inventory_item_id = kbn.inventory_item_id
    AND itm.organization_id = kbn.organization_id
    AND itm.inventory_item_id = moqd.inventory_item_id
    AND itm.organization_id = moqd.organization_id
    AND moqd.subinventory_code = kbn.source_subinventory
         AND kbn.card_status = 1
         AND kbn.supply_status = 5
         AND msc.inventory_item_id = itm.inventory_item_id
         AND msc.organization_id = itm.organization_id     
    GROUP BY
    kbn.last_update_date,itm.segment1,itm.description,kbn.kanban_card_number,kbn.kanban_size;
    Thanks
    Pravn

    Hi, Pravn,
    Remember the ABC's of GROUP BY:
    When you use a GROUP BY clause and/or an aggregate fucntion, then every item in the SELECT clause must be:
    (A) an <b>A</b>ggregate function,
    (B) one of the "group <b>B</b>y" expressions,
    (C) a <b>C</b>onstant, or
    (D) something that <b>D</b>epends entirely on the above. (For example, if you "GROUP BY TRUNC(dt)", you can "SELECT TO_CHAR (TRUNC(dt), 'Mon-DD')").
    There's a GROUP BY clause in your main query, so every item in the main SELECT clause must be one of the above. The last item, the unnamed scalar sub-query, is none of the above.
    How can you fix this problem? That depends on your data, the results you want, and perhaps on your Oracle version. If you'd like help, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved. Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Always say which version of Oracle you're using.
    You may have noticed that this site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (including, but limited to, actual code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Help!  Syntax Error in SQL statement

    Hello. I'm getting an error message and I'm just not seeing
    where I went wrong. The SQL statement is:
    updateSQL = "UPDATE TrainingHistory SET Status='" &
    fFormat(Request.Form(cStatus)) & "', StatusComments='" &
    fFormat(Request.Form(cStatusComments)) & " WHERE Training_ID="
    & fFormat(Request.Form(cTrainingID))
    The error message is:
    [Microsoft][ODBC Microsoft Access Driver] Syntax error in
    string in query expression '' WHERE Training_ID=9054'.
    I've been looking at it for a while. Not sure where I went
    wrong. Here is a more complete version of the code:
    <%
    Function fFormat(vText)
    fFormat = Replace(vText, "'", "''")
    End Function
    Sub sRunSQL(vSQL)
    set cExecute = Server.CreateObject("ADODB.Command")
    With cExecute
    .ActiveConnection = MM_coldsuncrea_lms_STRING
    .CommandText = vSQL
    .CommandType = 1
    .CommandTimeout = 0
    .Prepared = true
    .Execute()
    End With
    End Sub
    If Request.Form("action")="update" Then
    'Set variables for update
    Dim updateSQL, i
    Dim cTrainingID, cStatus, cStatusComments
    'Loop through records on screen and update
    For i = 1 To fFormat(Request.Form("counter"))
    'Create the proper field names to reference on the form
    cTrainingID = "Training_ID" & CStr(i)
    cStatus = "Status" & CStr(i)
    cStatusComments = "StatusComments" & CStr(i)
    'Create the update sql statement
    updateSQL = "UPDATE TrainingHistory SET Status='" &
    fFormat(Request.Form(cStatus)) & "', StatusComments='" &
    fFormat(Request.Form(cStatusComments)) & " WHERE Training_ID="
    & fFormat(Request.Form(cTrainingID))
    'Run the sql statement
    Call sRunSQL(updateSQL)
    Next
    'Refresh page
    Response.Redirect("ClassUpdateRoster.asp?Training_ID=") &
    (rsClassDetails.Fields.Item("event_ID").Value)
    End If
    %>

    You need another single quote after the double quote before
    the WHERE clause. You are not closing the single quote you used to
    delimit the value for StatusComments.

  • Sequence error in select statement

    Does anyone know why I get the following error when I run the code below. If so, how can it be fixed.
    Thanks in advance,
    John C
    ORA-02287 sequence number not allowed here
    INSERT INTO PROMO_STAGE.NAC_OFFER (CMPGN_KEY, OFFER_KEY, CREATIVE)
    SELECT DISTINCT A.CREATIVE,
    B.CMPGN_KEY,
    PROMO_STAGE.SEQ_NAC_OFFER_KEY.NEXTVAL@DSTAGE
    FROM PROMO_STAGE.CAMPAIGN@DSTAGE B,
    ROCEONOF.NACQ0211_2_FINAL@OGD A
    WHERE B.CMPGN_ID = 'NAC_'|| to_char(add_months(SYSDATE,-1),'YYYYMM');

    John
    It is the DISTINCT which is causing the trouble. How about:
    INSERT INTO PROMO_STAGE.NAC_OFFER (CMPGN_KEY, OFFER_KEY, CREATIVE)
    SELECT COL1, COL2, PROMO_STAGE.SEQ_NAC_OFFER_KEY.NEXTVAL@DSTAGE
    FROM
    (SELECT DISTINCT A.CREATIVE COL1, B.CMPGN_KEY COL2
    FROM PROMO_STAGE.CAMPAIGN@DSTAGE B,
    ROCEONOF.NACQ0211_2_FINAL@OGD A
    WHERE B.CMPGN_ID = 'NAC_'|| to_char(add_months(SYSDATE,-1),'YYYYMM'));
    Incidentally, judging by the column names, it appears that the columns in your insert statement are not listed in the same order as in the select statement, which of course they should be.

Maybe you are looking for