Using variables in the Select statement

Here is my Select statement:
Set EmpDynaset = OraDatabase.CreateDynaset("select CU_NAME,CU_CONTACT from CU where CU_Name =" & cnt, 0&)
What's wrong with this? I'm trying to use the variable cnt. Any help? Thanks, Jeremy

Here is my Select statement:
Set EmpDynaset = OraDatabase.CreateDynaset("select CU_NAME,CU_CONTACT from CU where CU_Name =" & cnt, 0&)
What's wrong with this? I'm trying to use the variable cnt. Any help? Thanks, Jeremy Perhaps using the following:
("select CU_NAME,CU_CONTACT from CU where CU_Name = :variable")
then binding the variable to a value before executing the statement..

Similar Messages

  • [php+mysql] how to use variables in a select statement?

    Hi all,
    I'm searching for a way to use a variable in the select
    statement of mysql
    query.
    I have this variable that can contain:
    $var=field_1 field_2 field5
    or
    $var=field3 field4 field8
    so, the variable content is not always the same.
    I would like to filter a table selecting only the columns
    specified by the
    current $var content.
    Is this possible to do something like this?
    $var=field1 field5 field10
    SELECT string_to_array($var)
    FROM mytable
    ORDER BY mysortfield ASC
    Or, is there another way to select columns dynamically?
    Thanks for any suggestion.
    tony

    Hi all,
    I'm searching for a way to use a variable in the select
    statement of mysql
    query.
    I have this variable that can contain:
    $var=field_1 field_2 field5
    or
    $var=field3 field4 field8
    so, the variable content is not always the same.
    I would like to filter a table selecting only the columns
    specified by the
    current $var content.
    Is this possible to do something like this?
    $var=field1 field5 field10
    SELECT string_to_array($var)
    FROM mytable
    ORDER BY mysortfield ASC
    Or, is there another way to select columns dynamically?
    Thanks for any suggestion.
    tony

  • Using Variables in a select statement through a Database Adapter

    I was wondering how I reference a variable in a select statement through a Database Adapter.
    Ex.
    1. I have a global variable that stores an employee number
    2. I want to select an SSN # from a table based on an employee #
    variable.
    select ssn from emp where ssn = :input_variable - ????
    - how do i reference the variable - I am getting a 'missing IN or OUT parameter error?
    Any advice is much appreciated.
    ~Thanks

    I'm just wondering if anyone knows a work around so that I might be able to store a Table's FIELD name in a variable or an array[] so that I can do a query based on the decision of a loop without having to code 10 IF/ELSE statements.For instance, although the above code will not work, this code, although quite lengthy, does:
    If DataGrid1.SelStartCol = 0 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES__PUR_DT"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 1 Then
    Adodc1.RecordSource = "Select * from tblReservation order by VENDOR"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 2 Then
    Adodc1.RecordSource = "Select * from tblReservation order by VEN_LOC"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 3 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_TYPE"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 4 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_FROM_DT"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 5 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_TO_DT"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 6 Then
    Adodc1.RecordSource = "Select * from tblReservation order by MISC_ADJ"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 7 Then
    Adodc1.RecordSource = "Select * from tblReservation order by STATE_TAX"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 8 Then
    Adodc1.RecordSource = "Select * from tblReservation order by LOC_CHARGE"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 9 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_ID"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 10 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_OP"
    Adodc1.Refresh
    End If
    Do you see where i'm going with this?
    I simple want to use a variable in the "select * from <Table> Order by <Field>"

  • How to use bind variable in this select statement

    Hi,
    I have created this procedure where table name and fieldname is variable as they vary, therefore i passed them as parameter. This procedure will trim leading (.) if first five char is '.THE''. The procedure performs the required task. I want to make select statement with bind variable is there any possibility to use a bind variable in this select statement.
    the procedure is given below:
    create or replace procedure test(tablename in varchar2, fieldname IN varchar2)
    authid current_user
    is
    type poicurtype is ref cursor;
    poi_cur poicurtype;
    sqlst varchar2(250);
    THEVALUE NUMBER;
    begin
         sqlst:='SELECT EMPNO FROM '||TABLENAME||' WHERE SUBSTR('||FIELDNAME||',1,5)=''.THE ''';
         DBMS_OUTPUT.PUT_LINE(SQLST);
    OPEN POI_CUR FOR SQLST ;
    LOOP
         FETCH POI_CUR INTO THEVALUE;
              EXIT WHEN POI_CUR%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE(THEVALUE);
              SQLST:='UPDATE '||TABLENAME|| ' SET '||FIELDNAME||'=LTRIM('||FIELDNAME||',''.'')';
              SQLST:=SQLST|| ' WHERE EMPNO=:X';
              DBMS_OUTPUT.PUT_LINE(SQLST);
                   EXECUTE IMMEDIATE SQLST USING THEVALUE;
    END LOOP;
    COMMIT;
    END TEST;
    Best Regards,

    So you want to amend each row individually? Is there some reason you're trying to make this procedure run as slow as possible?
    create or replace procedure test (tablename in varchar2, fieldname in varchar2)
    authid current_user
    is
       sqlst      varchar2 (250);
       thevalue   number := 1234;
    begin
       sqlst := 'update ' || tablename || ' set ' || fieldname || '= ltrim(' || fieldname || ',''.'')  where substr(' || fieldname
          || ',1,5) = ''.THE ''';
       dbms_output.put_line (sqlst);
       execute immediate sqlst;
    end test;will update every row that satisfies the criteria in a single statement. If there are 10 rows that start with '.THE ' then it will update 10 rows.

  • How to use presentaion variable in the SQL statement

    Is there any special syntax to use a presentation variable in the SQL Statement?
    I am setting a presentation variable (Fscl_Qtr_Var)in the dashboard prompt.
    If i set the filter as ADD->VARIABLE->PRESENTATION, it shows the statement as 'Contract Request Fiscal Quarter is equal to / is in @{Fscl_Qtr_Var} '.
    And this works fine but when i convert this to SQL, it returns
    "Contract Request Date"."Contract Request Fiscal Quarter" = 'Fscl_Qtr_Var'
    And this does not work.It is not being set to the value in the prompt.
    I need to combine this condition with other conditions in the SQL Statement. Any help is appreciated. Thanks

    Try this: '@{Fscl_Qtr_Var}'

  • Error while using selection option variable in the selection screen

    Hi All,
    I am facing an issue while using selection option variable in the selection screen for one of my reports.
    Scenario: For the field "Region From" we need to have wild card logic () in tes selection screen, for example if we put "BE" in the selection screen for the field Region From then the query should be executed only for those "Region From" values which begin from "BE".
    Approach: For the above requirement I have made a selection option variable for "Region From". This allows use wild card
    But when the report is executed we get the following error:
    "System error in program CL_RSR_REQUEST. Invalid filter on ETVRGNFR".
    (ETVRGNFR is technical name of the info object Region From)
    Though the report is executed it displays all the values for the field "Region From" irrespective of the selection given in the selection screen.
    Please give suggestions / alternate solutions to crack this issue.
    Thanks in advance
    Regards
    Priyanka.

    Hi,
    Try to use a variable of type Customer Exit and do the validation inside the exit to display according to your request.
    This is just my view, i am not sure if u are already using this or Char. Variable.
    Cheers.
    Ranga.

  • How can I call a Page Process from the Select statement for Report Page

    I'm able to call a javascript using the below:
    img src="#IMAGE_PREFIX#add2.gif" border="0" alt="Icon 4" onClick="javascript:add_connect1('||CPORT.ID||')"
    But Now,
    I'd like to accomplish (2) New things:
    1. instead of using,....... onClick="javascript:add_connect1,
    I'd like to call a Page Process, onClick=
    2. I'd like to be able to call two different processes onClick.
    a. onClick="javascript:passBack('||ID||')"
    b. onClick= <Please see my question #1 above>
    Can someone please help me with the syntax for this,
    If indeed it can even be done?
    Thanks- Gary

    Greg.
    It seems that my situation is the one you describe in you second paragraph, where you mention:
    you could then add the ID column value as a parameter to the javascript functionBut,
    I do not know how to reference the variable in my javascript nor how to use it in my on-demand process.
    If you can hellp me past this last little bump, then I think I will be able to use these skills in Sooo many different areas of my design.
    Here's what I've got so far:
    A. In the select statement I identify the javascript as:
    onClick="javascript:connect_port('<font color=blue>''||ID||''</font>')";
    B. In my javascript I have this:
    <script language="JavaScript" type="text/javascript">
    function connect_port(ID)
    var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=CONNECT_PORT',0);
    gReturn = get.get();
    get = null;
    </script>
    C. In my on demand function I have this:
    BEGIN
    INSERT INTO CCONNECTIONS_B
    BLDG_ID,CLST_ID,PORT_ID,STRAND_ID
    ) VALUES
    :P2004_BLDG_ID,:P2004_CLST_ID,:P2004_PORT_ID,:P2004_STRAND_ID1
    END;
    You can see that I dont know how to use the value for 'ID' in either the javascript or the On-Process function.
    If you can help me out with this one, Then I can imitate it for the rest.
    -Gary
    Edited by: garyNboston on Apr 3, 2009 6:44 AM
    Edited by: garyNboston on Apr 3, 2009 6:44 AM
    Edited by: garyNboston on Apr 3, 2009 6:45 AM
    Edited by: garyNboston on Apr 3, 2009 6:47 AM

  • Merge can't accept a variable in the select clause?

    oracle 10.2
    I have a stored procedure.
    I have a variable, vseq, which I set a sequence variable. With all other sql statements I can do
    insert into table a
    select vseq
    from dual;
    Apparently a merge can't handle variables in the select clause. I get an error. I can get it to work when I hard code a value.
    this is ridiculous...

    merge can't handle variables in the select clauseCare to prove?
    sql> DECLARE
      2   v_first_name varchar2(20) := 'BOSS';
      3  BEGIN
      4  MERGE INTO sun_employees se
      5  USING (SELECT * FROM employees WHERE department_id = 20) e
      6  ON (e.employee_id = se.employee_id)
      7  WHEN MATCHED THEN
      8    UPDATE SET salary = e.salary
      9  WHEN NOT MATCHED THEN
    10  INSERT(employee_id, first_name, last_name, department_id)
    11  VALUES (e.employee_id, v_first_name, e.last_name, e.department_id);
    12  END;
    13  /
    PL/SQL procedure successfully completed.
    sql> select first_name from sun_employees;
    FIRST_NAME
    BOSS
    BOSS

  • How to populate the ranges using FM for the SELECTs

    Hi,
    I am still working on the FM to create a generic extractor. I went through the debugger but I am still unable to determine how the ranges are populated. RSA3 always gives me zero values for the results.
    There is a RANGE statement in the sample FM and the following statements for SELECTs
      RANGES: L_R_CARRID  FOR SFLIGHT-CARRID,
              L_R_CONNID  FOR SFLIGHT-CONNID.
    and...
          LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'CARRID'.
            MOVE-CORRESPONDING L_S_SELECT TO L_R_CARRID.
            APPEND L_R_CARRID.
          ENDLOOP.
          LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = 'CONNID'.
            MOVE-CORRESPONDING L_S_SELECT TO L_R_CONNID.
            APPEND L_R_CONNID.
          ENDLOOP.
    My question is how is L_R_CONNID and L_R_CARRID populated with low and high values for the SELECT statements? I tried to find the DS 0SAPI_SFLIGHT_SIMPLE to run and see how it is set up but there is no such DS.
    Would someone take the time to say something about this in  several sentences? I have my own code and it seems that it is not populating the values for the SELECTs when I debug from RSA3 when I provide the low and high values.
    Would I normally populate the low and high values from the InfoPackage 'Data Selection' tab once I have implemented in BW or ready to test in BW? That would mean I have to choose those fields as selections from RSO2. Anyway, I think I have asked about this but I am hoping to get an answer to get this going...
    Appreciate any replies.

    Hi
    Here is an example of an extractor that uses
    both method's, if the InfoPackage selection exist's
    it overrides the TVARV selection (which is the default).
    FUNCTION ZBW_TC_FORECAST_SO_EXTRACTOR.
    ""Local interface:
    *"  IMPORTING
    *"     VALUE(I_REQUNR) TYPE  SBIWA_S_INTERFACE-REQUNR
    *"     VALUE(I_DSOURCE) TYPE  SBIWA_S_INTERFACE-ISOURCE OPTIONAL
    *"     VALUE(I_CHABASNM) TYPE  SBIWA_S_INTERFACE-CHABASNM OPTIONAL
    *"     VALUE(I_MAXSIZE) TYPE  SBIWA_S_INTERFACE-MAXSIZE OPTIONAL
    *"     VALUE(I_INITFLAG) TYPE  SBIWA_S_INTERFACE-INITFLAG OPTIONAL
    *"     VALUE(I_UPDMODE) TYPE  SBIWA_S_INTERFACE-UPDMODE OPTIONAL
    *"     VALUE(I_DATAPAKID) TYPE  SBIWA_S_INTERFACE-DATAPAKID OPTIONAL
    *"     VALUE(I_PRIVATE_MODE) OPTIONAL
    *"     VALUE(I_CALLMODE) TYPE  ROARCHD200-CALLMODE OPTIONAL
    *"  TABLES
    *"      I_T_SELECT TYPE  SBIWA_T_SELECT OPTIONAL
    *"      I_T_FIELDS TYPE  SBIWA_T_FIELDS OPTIONAL
    *"      E_T_DATA STRUCTURE  ZBW_TC_FORECASTING_EXT_STR OPTIONAL
    *"  EXCEPTIONS
    *"      NO_MORE_DATA
    *"      ERROR_PASSED_TO_MESS_HANDLER
    *"      HIERARCHY_NOT_FOUND
    Change History                                                      *
    Mod. #  |  Date    |  Developer     |  Description                  *
    *RD3K915762|06/21/2005| SRangaraj      | Change selection of open SO   *
             |          |                | data to include deleted matls *
             |          |                | and obsolete items too        *
    RD3K915888|06/29/2005| SRANGARAJ      | Add ext matl grp and lab offce
             |          |                | filters for data-selection    *
    The input parameter I_DATAPAKID is not supported yet !
    Auxiliary Selection criteria structure
      DATA: L_S_SELECT TYPE SBIWA_S_SELECT.
    Maximum number of lines for DB table
      STATICS L_MAXSIZE TYPE SBIWA_S_INTERFACE-MAXSIZE.
    Parameter I_PRIVATE_MODE:
    Some applications might want to use this function module for other
    purposes as well (e.g. data supply for OLTP reporting tools). If the
    processing logic has to be different in this case, use the optional
    parameter I_PRIVATE_MODE (not supplied by BIW !) to distinguish
    between BIW calls (I_PRIVATE_MODE = SPACE) and other calls
    (I_PRIVATE_MODE = X).
    If the message handling has to be different as well, define Your own
    messaging macro which interprets parameter I_PRIVATE_MODE. When
    called by BIW, it should use the LOG_WRITE macro, otherwise do what
    You want.
    Initialization mode (first call by SAPI) or data transfer mode
    (following calls) ?
      IF I_INITFLAG = SBIWA_C_FLAG_ON.
    Initialization: check input parameters
                    buffer input parameters
                    prepare data selection
    The input parameter I_DATAPAKID is not supported yet !
    Invalid second initialization call -> error exit
        IF NOT G_FLAG_INTERFACE_INITIALIZED IS INITIAL.
          IF 1 = 2. MESSAGE E008(R3). ENDIF.
          LOG_WRITE 'E'                    "message type
                    'R3'                   "message class
                    '008'                  "message number
                    ' '                    "message variable 1
                    ' '.                   "message variable 2
          RAISE ERROR_PASSED_TO_MESS_HANDLER.
        ENDIF.
    Check InfoSource validity
        CASE I_DSOURCE.
          WHEN 'ZBW_TC_SO_EXTRACT'.
          WHEN OTHERS.
            IF 1 = 2. MESSAGE E009(R3). ENDIF.
            LOG_WRITE 'E'                  "message type
                      'R3'                 "message class
                      '009'                "message number
                      I_DSOURCE            "message variable 1
                      ' '.                 "message variable 2
            RAISE ERROR_PASSED_TO_MESS_HANDLER.
        ENDCASE.
    Check for supported update mode
       CASE I_UPDMODE.
         WHEN 'F'.
         WHEN OTHERS.
           IF 1 = 2. MESSAGE E011(R3). ENDIF.
           LOG_WRITE 'E'                  "message type
                     'R3'                 "message class
                     '011'                "message number
                     I_UPDMODE            "message variable 1
                     ' '.                 "message variable 2
           RAISE ERROR_PASSED_TO_MESS_HANDLER.
       ENDCASE.
    Check for obligatory selection criteria
       READ TABLE I_T_SELECT INTO L_S_SELECT WITH KEY FIELDNM = 'PGMID'.
       IF SY-SUBRC <> 0.
         IF 1 = 2. MESSAGE E010(R3). ENDIF.
         LOG_WRITE 'E'                    "message type
                   'R3'                   "message class
                   '010'                  "message number
                   'PGMID'                "message variable 1
                   ' '.                   "message variable 2
         RAISE ERROR_PASSED_TO_MESS_HANDLER.
       ENDIF.
        APPEND LINES OF I_T_SELECT TO G_T_SELECT.
    Fill parameter buffer for data extraction calls
        G_S_INTERFACE-REQUNR    = I_REQUNR.
        G_S_INTERFACE-ISOURCE   = I_DSOURCE.
        G_S_INTERFACE-MAXSIZE   = I_MAXSIZE.
        G_S_INTERFACE-INITFLAG  = I_INITFLAG.
        G_S_INTERFACE-UPDMODE   = I_UPDMODE.
        G_S_INTERFACE-DATAPAKID = I_DATAPAKID.
        G_FLAG_INTERFACE_INITIALIZED = SBIWA_C_FLAG_ON.
    Fill field list table for an optimized select statement
    (in case that there is no 1:1 relation between InfoSource fields
    and database table fields this may be far from beeing trivial)
        APPEND LINES OF I_T_FIELDS TO G_T_FIELDS.
    Fill range tables for fixed InfoSources. In the case of generated
    InfoSources, the usage of a dynamical SELECT statement might be
    more reasonable. BIW will only pass down simple selection criteria
    of the type SIGN = 'I' and OPTION = 'EQ' or OPTION = 'BT'.
        LOOP AT G_T_SELECT INTO L_S_SELECT.
          CASE L_S_SELECT-FIELDNM.
            WHEN 'PRDHA'.
              WGF_PRDHA_LENGTH = STRLEN( L_S_SELECT-LOW ).
              IF WGF_PRDHA_LENGTH = 6.  "PARTIAL PRDHA
                 WGF_PRDHA = L_S_SELECT-LOW.
                 CONCATENATE WGF_PRDHA '%' INTO WGF_PRDHA.
              ELSEIF WGF_PRDHA_LENGTH = 12.  "FULL PRDHA
              MOVE-CORRESPONDING L_S_SELECT TO L_R_PRDHA.
              APPEND L_R_PRDHA.
              ENDIF.
            WHEN 'MATKL'.
              MOVE-CORRESPONDING L_S_SELECT TO L_R_MATKL.
              APPEND L_R_MATKL.
          ENDCASE.
        ENDLOOP.
    reset the index of where we are in the gt_header table
      g_tabix = 0.
      perform populate_default_variables.
      perform get_data.
      perform build_detail.
        EXIT.
      ENDIF.                 "Initialization mode or data extraction ?
    Data transfer: First Call      OPEN CURSOR + FETCH
                   Following Calls FETCH only
    First data package -> OPEN CURSOR
       IF G_COUNTER_DATAPAKID = 0.
    Determine number of database records to be read per FETCH statement
    from input parameter I_MAXSIZE. If there is a one to one relation
    between InfoSource table lines and database entries, this is trivial.
    In other cases, it may be impossible and some estimated value has to
    be determined.
      DESCRIBE TABLE LT_DATA LINES l_count.
      IF g_tabix GE l_count.
        RAISE no_more_data.
      ENDIF.
    *CLEAN UP THE OUTPUT TABLE
      refresh E_T_DATA.
      LOOP AT LT_DATA FROM G_TABIX INTO LS_DATA.
        APPEND LS_DATA TO E_T_DATA.
    Set global counter
        g_tabix = g_tabix + 1.
      ENDLOOP.
       G_COUNTER_DATAPAKID = G_COUNTER_DATAPAKID + 1.
    ENDIF.              "Initialization mode or data extraction ?
    ENDFUNCTION.
    Forms
    ***INCLUDE LZBW_TC_FORECAST_SO_EXTF01 .
    *&      Form  populate_default_variables
          text
    -->  p1        text
    <--  p2        text
    FORM populate_default_variables.
      data: wlf_name like tvarv-name.
      clear: R_prdh3[], wlf_name.
    *get the exclusion range from tvarv for the product hierarchy in
    *question
      concatenate 'ZBW_EXL_' WGF_PRDHA(6) INTO WLF_NAME.
    SELECT LOW FROM TVARV INTO R_prdh3-low WHERE
                                 NAME = WLF_NAME.
      move:  'I'    to R_prdh3-sign,
             'EQ'   to R_prdh3-option.
      append R_prdh3.
      clear R_prdh3.
    ENDSELECT.
    {Start of insert by SRangaraj on June 29, 2005 >>RD3K915888
    CLEAR L_R_LABOR[].
    SELECT LOW FROM TVARV INTO L_R_LABOR-Low WHERE
                                 NAME = 'ZBW_TC_FORECAST_LAB_OFF'.
      move:  'I'    to L_R_LABOR-sign,
             'EQ'   to L_R_LABOR-option.
      append L_R_LABOR.
      clear L_R_LABOR.
    ENDSELECT.
    }End of insert by SRangaraj on June 29, 2005 >>RD3K915888
    ENDFORM.                    " populate_default_variables
    *&      Form  get_data
          text
    -->  p1        text
    <--  p2        text
    FORM get_data.
      data: wlf_lmeng like vbep-lmeng.
    *get all deliveries for date range for either a range of product hrchy
    *or a like value
      refresh int_records1.
      if wgf_prdha ne space.
        select ivbeln iposnr iKLMENG jvkorg i~werks
               imatnr imeins mprdha mmatkl
        from vbap as i
           INNER JOIN VBAK AS j
           ON ( jvbeln = ivbeln
                and j~vbtyp = 'C' )
           INNER JOIN vbuk AS k
           ON ( kvbeln = ivbeln
                and k~lfgsk <> 'C'
                and k~gbstk <> 'C' )
           INNER JOIN vbup AS l
           ON ( lvbeln = ivbeln and
                lposnr = iposnr
                and l~lfgsa <> 'C'
                and l~gbsta <> 'C' )
           INNER JOIN mara AS m
           ON ( mmatnr = imatnr
    {Start of insert by SRangaraj on June 21, 2005 >>RD3K915762
                and m~lvorm eq ' '
                and m~mstae ne '99'
    {Start of insert by SRangaraj on June 29, 2005 >>RD3K915888
                and m~extwg = '080' )
    }End of insert by SRangaraj on June 29, 2005 >>RD3K915888
           INNER JOIN marc AS n
           ON ( nmatnr = imatnr
                and nwerks = iwerks
                and n~lvorm eq ' ' )
    }End of insert by SRangaraj on June 21, 2005 >>RD3K915762
        into table int_records1 where ( i~abgru = '  '
                                     and i~klmeng > 0
                                     and m~prdha like wgf_prdha
                                     and m~matkl in l_r_matkl
    {Start of insert by SRangaraj on June 29, 2005 >>RD3K915888
                                     and m~labor in l_r_labor ).
    }End of insert by SRangaraj on June 29, 2005 >>RD3K915888
      elseif not l_r_prdha[] is initial and wgf_prdha = space.
        select ivbeln iposnr iKLMENG jvkorg i~werks
               imatnr imeins mprdha mmatkl
        from vbap as i
           INNER JOIN VBAK AS j
           ON ( jvbeln = ivbeln
                and j~vbtyp = 'C' )
           INNER JOIN vbuk AS k
           ON ( kvbeln = ivbeln
                and k~lfgsk <> 'C'
                and k~gbstk <> 'C' )
           INNER JOIN vbup AS l
           ON ( lvbeln = ivbeln and
                lposnr = iposnr
                and l~lfgsa <> 'C'
                and l~gbsta <> 'C' )
           INNER JOIN mara AS m
           ON ( mmatnr = imatnr
    {Start of insert by SRangaraj on June 21, 2005 >>RD3K915762
                and m~lvorm eq ' '
                and m~mstae ne '99'
    {Start of insert by SRangaraj on June 29, 2005 >>RD3K915888
                and m~extwg = '080' )
    }End of insert by SRangaraj on June 29, 2005 >>RD3K915888
           INNER JOIN marc AS n
           ON ( nmatnr = imatnr
                and nwerks = iwerks
                and n~lvorm eq ' ' )
    }End of insert by SRangaraj on June 21, 2005 >>RD3K915762
        into table int_records1 where ( i~abgru = '  '
                                     and i~klmeng > 0
                                     and m~prdha in l_r_prdha
                                     and m~matkl in l_r_matkl
    {Start of insert by SRangaraj on June 29, 2005 >>RD3K915888
                                     and m~labor in l_r_labor ).
    }End of insert by SRangaraj on June 29, 2005 >>RD3K915888
    endif.
        sort int_records1 by vbeln posnr.
        delete adjacent duplicates from int_records1 comparing
        vbeln posnr.
    *remove unnecessary records
        if not r_prdh3[] is initial.
        DELETE INT_RECORDS1 WHERE PRDHA+6(3) IN r_prdh3.
        endif.
    *get the schedule lines for all of the above records and
    *get the lowest schedule line date per so line item
         if not int_records1[] is initial.
         refresh int_records3.
         select vbeln posnr etenr mbdat into table int_records3
         from vbep for all entries in int_records1
                           where vbeln = int_records1-vbeln and
                                 posnr = int_records1-posnr and
                                 lmeng > 0.
         sort int_records3 by vbeln posnr etenr mbdat ascending.
         loop at int_Records1.
           loop at int_records3 where vbeln = int_records1-vbeln
                                  and posnr = int_records1-posnr.
             int_records1-mbdat = int_records3-mbdat.
             modify int_records1.
             exit.
            endloop.
         endloop.
         refresh int_records3. free int_records3.
         refresh int_records2.
    *get the deliveries and calculate the open quantities
        select vbelv posnv vbeln posnn rfmng plmin
                    from vbfa into table int_records2
                                  for all entries in int_Records1
                                  where vbelv = int_records1-vbeln
                                    and posnv = int_records1-posnr
                                    and VBTYP_N = 'J'. "Dels
    *calculate open quantities next
         loop at int_records1.
           clear wlf_lmeng.
           clear int_records2.
           loop at int_records2 where vbelv = int_records1-vbeln
                                    and posnv = int_records1-posnr.
           case int_records2-plmin.
             when '-'.
              wlf_lmeng = wlf_lmeng - int_records2-rfmng.
             when others.  "just add
              wlf_lmeng = wlf_lmeng + int_records2-rfmng.
            endcase.
           endloop.
           int_records1-klmeng = int_records1-klmeng - wlf_lmeng.
           int_records1-vbeln_dl = int_records2-vbeln.
           int_records1-posnr_dl = int_records2-posnn.
           modify int_records1.
        endloop.
        endif.
        delete int_records1 where klmeng le 0.
        refresh int_records2. free int_Records2.
    ENDFORM.                    " get_data
    *&      Form  build_detail
          text
    -->  p1        text
    <--  p2        text
    FORM build_detail.
        LOOP AT int_records1.
    *DO INDIVIDUAL MOVES - ITS FASTER THAN MOVE-CORRESPONDING
        move: int_records1-vkorg    to LS_DATA-VKORG,
              int_records1-werks    to LS_DATA-WERKS,
              int_records1-matnr    to LS_DATA-MATNR,
              int_records1-klmeng   to LS_DATA-KLMENG,
              int_records1-mbdat(6) to LS_DATA-YEARMONTH,
              int_records1-meins    TO LS_DATA-MEINS,
              int_records1-vbeln    TO LS_DATA-VGBEL,
              int_records1-posnr    TO LS_DATA-VGPOS,
              int_records1-vbeln_dl TO LS_DATA-VBELN,
              int_records1-posnr_dl TO LS_DATA-POSNR,
              int_records1-mbdat    to LS_DATA-WADAT_IST,
              int_records1-PRDHA    to LS_DATA-PRDHA,
              int_records1-matkl    to LS_DATA-MATKL.
        APPEND LS_DATA TO LT_DATA.
        clear: LS_DATA.
        ENDLOOP.
    ENDFORM.                    " build_detail

  • Error by using database procedure in select statement

    hi ,
    I have built a database procedure having one parameter with in out varchar type. that return value with some addition.
    i am using it with some column in select statement only for display purpuses but i am facing error by doing that in select statement. that procedure is working well with bind variable but not with select statement.
    plz help me how i can use a procedure in select statement. or can i do it or not.

    plz help me how i can use a procedure in select statement. or can i do it or not.A workaround could be to create a wrapper function for your procedure. One that only passes the input parameters and returns the output parameter.
    The simply call this function in your select which internally calls the procedure.

  • Using Variables in a SQL Statement

    I know, I know, this is written in VB..I'm doing a VB Project right now for my Instructor (While in an Intermediate Java Class)
    But VB (I feel) doesnt have very good support Forums.
    Anyway, this is the problem:
    I want to use String Variables to hold the place of field names in
    a SQL Statement and the change the ORDER according to intCount's Loop:
    The key word(s) here is "ORDER BY"
    Private Sub DataGrid1_Click()
    Dim intCount As Integer
    Dim strColHead(11) As String
    strColHead(0) = "RES__PUR_DT"
    strColHead(1) = "VENDOR"
    strColHead(2) = "VEN_LOC"
    strColHead(3) = "RES_TYPE"
    strColHead(4) = "RES_FROM_DT"
    strColHead(5) = "RES_TO_DT"
    strColHead(6) = "MISC_ADJ"
    strColHead(7) = "STATE_TAX"
    strColHead(8) = "LOC_CHARGE"
    strColHead(9) = "RES_ID"
    strColHead(10) = "RES_OP"
    For intCount = 0 To 10
    If DataGrid1.SelStartCol = intCount Then
    Adodc1.RecordSource = "Select * from tblReservation order by 'strColHead(intCount)'"
    End If
    Adodc1.Refresh
    Next intCount
    End Sub

    I'm just wondering if anyone knows a work around so that I might be able to store a Table's FIELD name in a variable or an array[] so that I can do a query based on the decision of a loop without having to code 10 IF/ELSE statements.For instance, although the above code will not work, this code, although quite lengthy, does:
    If DataGrid1.SelStartCol = 0 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES__PUR_DT"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 1 Then
    Adodc1.RecordSource = "Select * from tblReservation order by VENDOR"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 2 Then
    Adodc1.RecordSource = "Select * from tblReservation order by VEN_LOC"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 3 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_TYPE"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 4 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_FROM_DT"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 5 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_TO_DT"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 6 Then
    Adodc1.RecordSource = "Select * from tblReservation order by MISC_ADJ"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 7 Then
    Adodc1.RecordSource = "Select * from tblReservation order by STATE_TAX"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 8 Then
    Adodc1.RecordSource = "Select * from tblReservation order by LOC_CHARGE"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 9 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_ID"
    Adodc1.Refresh
    ElseIf DataGrid1.SelStartCol = 10 Then
    Adodc1.RecordSource = "Select * from tblReservation order by RES_OP"
    Adodc1.Refresh
    End If
    Do you see where i'm going with this?
    I simple want to use a variable in the "select * from <Table> Order by <Field>"

  • Using Multiple Parameters in Select Statement

    My goal is to be able to use more than one parameter for the select statement.  When I use OR instead of AND it works but with only one parameter. I thought using AND would return any parameter that is listed in the  ?Report Based On}. Any ideas why this will not work?
    I've created four parameters:
    Report Based on (string)  Allow Multiple Values (Default Values: Customer, Part Id, and Serial Number)
    RMA info by Customer  (string)
    RMA Info by Part Id  (string)
    RMA Info by SN  (string)
    This is my select statement
    (if {?Report Based On} = "Customer" then
        {RMA_Information.Customer}LIKE{?RMA info by Customer})
    and
    (if {?Report Based On} = "Part Id" then
    {RMA_Information.Part Id}LIKE{?RMA Info by Part Id})
    and
    (if {?Report Based On} = "Serial Number" then
      {RMA_Information.Serial Number}={?RMA Info by SN })
    tx Shirley

    Try this...
    IF "Customer" IN {?Report Based On} AND
         "Part Id" IN {?Report Based On} AND
         "Serial Number" IN {?Report Based On}
    THEN {RMA_Information.Customer}LIKE{?RMA info by Customer} AND
         {RMA_Information.Part Id}LIKE{?RMA Info by Part Id} AND
         {RMA_Information.Serial Number}={?RMA Info by SN}
    ELSE
    IF "Customer" IN {?Report Based On} AND
         "Part Id" IN {?Report Based On}
    THEN {RMA_Information.Customer}LIKE{?RMA info by Customer} AND
         {RMA_Information.Part Id}LIKE{?RMA Info by Part Id}
    ELSE
    IF "Customer" IN {?Report Based On} AND
         "Serial Number" IN {?Report Based On}
    THEN {RMA_Information.Customer}LIKE{?RMA info by Customer} AND
         {RMA_Information.Serial Number}={?RMA Info by SN}
    ELSE
    IF "Part Id" IN {?Report Based On} AND
         "Serial Number" IN {?Report Based On}
    THEN {RMA_Information.Part Id}LIKE{?RMA Info by Part Id} AND
         {RMA_Information.Serial Number}={?RMA Info by SN}
    ELSE
    IF "Customer" IN {?Report Based On}
    THEN {RMA_Information.Customer}LIKE{?RMA info by Customer}
    ELSE
    IF "Part Id" IN {?Report Based On}
    THEN {RMA_Information.Part Id}LIKE{?RMA Info by Part Id}
    ELSE
    "Serial Number" IN {?Report Based On}
    THEN {RMA_Information.Serial Number}={?RMA Info by SN}
    HTH,
    Jason

  • Using @Prompt in the SELECT clause (?)

    Post Author: faltinowski
    CA Forum: Semantic Layer and Data Connectivity
    Product:  Business Objects
    Version:  6.5 SP3 
    Patches Applied:  MHF11 and CHF48
    Operating System(s):  Windows
    Database(s):  Oracle
    Error Messages:  "Parse failed: Exception: DBD, ORA-00903 invalid table name  State N/A"
    Hi!  I'm bewildered -- we have an object that parses but when I try to reproduce this object, it does not.
    We have a universe that's been in production for several years using an object developed by another designer who's no longer with the company.  This object is a dimension, datatype is character, and there's no LOV associated.  The SELECT statement in this object is
    decode(@Prompt('Select Snapshot Month','A','Object Definitions\CY Month Snapshot',MONO,CONSTRAINED),'00-Previous Month',to_number(to_char(add_months(sysdate,-1),'MM')),'01-Current Month',to_number(to_char(add_months(sysdate,0),'MM')),'01-January','1','02-February','2','03-March','3','04-April','4','05-May','5','06-June','6','07-July','7','08-August','8','09-September','9','10-October','10','11-November','11','12-December','12')
    This object parses. The client uses the object in the select clause to capture the "month of interest" for the report.  So the report may be for the entire year's data which is graphed to show trends, but there's a table below the graph which is filtered to show just the month of interest.  Typically they use the value "00-Previous Month" so they can schedule the report and it will always show the last month's data.
    Problem
    The original object parses.
    If I copy the object within the same universe, it parses.
    If I copy the code into a new object in the same universe, it doesn't parse
    If I copy the code into a new object in a different universe, it doesn't parse
    If I copy the object to a different universe, then edit the LOV reference, it doesn't parse
    If I create any new object having @Prompt in the SELECT statement, it doesn't parse.
    If another designer tries - they get the same thing.
    What am I missing?  Obviously someone was able to create this successfully.
    On the brighter side
    The object I created in a new universe (which doesn't parse in the universe) seems to work fine in the report.

    Seems that, the prompt syntax is correct.
    But the condition is not correct.
    You are taking the prompt value and not doing anything. That could be one issue for this error.
    I believe that, you just want to capture the prompt value use it in report level and do not want to apply as a filter.
    So, use the condition as follows.
    @Prompt('Select Grouping','A',{'A','B','C'},mono,constrained) = @Prompt('Select Grouping','A',{'A','B','C'},mono,constrained)
    Hope this helps!

  • How to use SET ID in select statement of SQ02

    Hi,
    I have a infoset, where for one of my Zfield, i have writen a select statement in order to get my ouput.
    if aufk-aufnr = 'XYZ'.
      select sum( FKBTR ) from fmifiit into zfmifiit
      where fikrs = aufk-kokrs
      and fipex IN capex
      and wrttp NE '51'.
    endif.
    For the above statement, i have created (with 10 single values, table name FMCI, field name FIPEX)  a SET id named CAPEX and used with IN operator.
    But when i generating the infoset i am getting error like below
    The IN operator with "CAPEX" is followed neither by an internal table nor by a value list
    I was using IN opeartor for set ids during validation / substitutions, where if i have to validate multiple single values.
    What to do here?
    Regards,
    Srinu

    [OPEN-SQL|http://help.sap.com/abapdocu_70/en/ABENOPEN_SQL_GENERAL.htm] set of statement, [SELECT|http://help.sap.com/abapdocu_70/en/ABAPWHERE.htm] statement, [WHERE|http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP.htm] addition requires a selection table (type range, [WHERE - IN seltab |http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_SELTAB.htm]) of parameter and not a set. We are in Abap here, not in a Customizing screen
    You have to convert the set to a selection table in an ABAP coding before using it in a SELECT statement.
    (Check FM like G_SET_TREE_IMPORT to import definition of set (values and intervals) and map them to a select-table, or ask a developper to perform it, look at G_SET_TREE_IMPORT -> select statement)
    Regards,
    Raymond

  • Use of wildcard * in SELECT statement

    I have read that the use of the wildcard * in a SELECT statement cannot be utilized when using the INSERT INTO or other queries where data column/field alignment is critical. I have noted that the INSERT INTO column/fields must be in the same order
    as the SELECT statement (as there is no alignment to column/field names). Can someone please provide me with the information or article that covered this scenario?

    It is consider a good practice to specify columns name, however , SQL Server is smart enough to insert the data without too , but only if the table does not have an IDENTITY property
    CREATE TABLE #t (c1 int, c2 char(1),c3 real, c4 bit)
    CREATE TABLE #t1 (c1 int, c2 char(1),c3 real, c4 bit)
    ---Same thing with INSERT  like SELECT * you asked
    INSERT INTO #t1 VALUES (1,'A',2.5,0) 
    INSERT INTO #t1 VALUES (2,'B',3.5,1)
    INSERT INTO #t1 VALUES (3,'C',4.5,0)
    INSERT INTO #t SELECT * FROM #t1
    SELECT * FROM #t
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

Maybe you are looking for