String compare in select statement

Hi All,
i have a problem in select statement. i have a name field in my selection screen, i am using name field to comapre string in my select statement, but i am not getting the resule can anyone suggest me on this . please find my code below,s_name1 is my select option name.
IF s_name1-low IS NOT INITIAL.
LOOP AT S_NAME1.
  CONCATENATE s_name1-low '%' INTO s_name1-low.
  TRANSLATE s_name1-low TO UPPER CASE.
  s_name1-option = 'CP'.
  MODIFY s_name1.
ENDLOOP.
ENDIF.
SELECT lifnr land1 name1 ort01 ort02 pfach pstl2 pstlz regio stras
         erdat ernam ktokk loevm sperr sperm sperz nodel
    INTO (gs_vendor-vendor_num, gs_vendor-land1, gs_vendor-name,
          gs_vendor-ort01, gs_vendor-ort02, gs_vendor-pfach,
          gs_vendor-pstl2, gs_vendor-pstlz, gs_vendor-regio,
          gs_vendor-stras, gs_vendor-created_on, gs_vendor-created_by,
          gs_vendor-account_gp, gs_vendor-deletion_flag,
          gs_vendor-central_post, gs_vendor-ctr_purch_block,
          gs_vendor-payment_block, gs_vendor-central_deletion)
    FROM  lfa1
         WHERE  lifnr  IN s_lifnr
         AND    name1  LIKE s_name1
Start of Change G9007789 03/12/2008 - D01K946651
Additional selection criteria added for City and Region
         AND    ort01  IN s_ort01
         AND    regio  IN s_regio
End of Change G9007789 03/12/2008 - D01K946651
         AND    ktokk  IN s_ktokk
         AND    ( ktokk  NE 'ZHMT' AND ktokk NE 'ZTER' ).
    APPEND gs_vendor TO gt_vendor.
    CLEAR gs_vendor.
  ENDSELECT.

Hi,
Have you checked whether you have given proper events.
Check this code below.
AT selection screen output. "Change here
IF s_name1-low IS NOT INITIAL.
LOOP AT S_NAME1.
CONCATENATE s_name1-low '%' INTO s_name1-low.
TRANSLATE s_name1-low TO UPPER CASE.
s_name1-option = 'CP'.
MODIFY s_name1.
ENDLOOP.
ENDIF.
Start-of-Selection. " change here
SELECT lifnr land1 name1 ort01 ort02 pfach pstl2 pstlz regio stras
erdat ernam ktokk loevm sperr sperm sperz nodel
INTO (gs_vendor-vendor_num, gs_vendor-land1, gs_vendor-name,
gs_vendor-ort01, gs_vendor-ort02, gs_vendor-pfach,
gs_vendor-pstl2, gs_vendor-pstlz, gs_vendor-regio,
gs_vendor-stras, gs_vendor-created_on, gs_vendor-created_by,
gs_vendor-account_gp, gs_vendor-deletion_flag,
gs_vendor-central_post, gs_vendor-ctr_purch_block,
gs_vendor-payment_block, gs_vendor-central_deletion)
FROM lfa1
WHERE lifnr IN s_lifnr
AND name1 LIKE s_name1
Start of Change G9007789 03/12/2008 - D01K946651
Additional selection criteria added for City and Region
AND ort01 IN s_ort01
AND regio IN s_regio
End of Change G9007789 03/12/2008 - D01K946651
AND ktokk IN s_ktokk
AND ( ktokk NE 'ZHMT' AND ktokk NE 'ZTER' ).
APPEND gs_vendor TO gt_vendor.
CLEAR gs_vendor.
ENDSELECT.
Reward if helpful.
Regards.

Similar Messages

  • How to coerce data types to strings in a SELECT statement?

    ABAPers,
    I need to coerce column outputs to strings in a SELECT statement. Here is a pseudo example:
    select ConvertToString(count(*)) from MARA
    On help.sap.com, I could not find enough information on the functions that are supported within SELECT statement. I would appreciate it if someone can enlighten me on how to achive this.
    Note that my real problem is that I do not know the return type of the specified columns. The columns are passed as a user-specified parameter. As I do not know the column types, I am mandating that customers specify columns that return only string type data.
    Thank you in advance for your help.
    Pradeep

    Hi Pradeep,
    Convert to string wont be possible in the SELECT statement.
    What you can do is use Field Symbols. This allows to assign data types dynamically.
    Field-Symbols
    Best regards,
    Prashant
    Pls. mark points for helpful answers

  • Executing String which  has SELECT statement

    String stmt:='Select * from Table a';
    How do I execute the select statement present in the string.
    Thanks for the help in advance

    In most cases this is something you should not be doing on a regular basis. Also when using dynamic sql, take care to use bind variables.
    SQL> create or replace function f (p_stmt varchar2)
      2  return sys_refcursor as
      3    c sys_refcursor;
      4  begin
      5    open c for p_stmt;
      6    return c;
      7  end;
      8  /
    Function created.
    SQL> var c refcursor
    SQL> exec :c := f('select * from emp')
    PL/SQL procedure successfully completed.
    SQL> print c
    EMPNO ENAME      JOB          MGR HIREDATE     SAL   COMM DEPTNO
      7369 SMITH      CLERK       7902 17-DEC-80    800            20
      7499 ALLEN      SALESMAN    7698 20-FEB-81   1600    300     30
      7521 WARD       SALESMAN    7698 22-FEB-81   1250    500     30
      7566 JONES      MANAGER     7839 02-APR-81   2975            20
      7654 MARTIN     SALESMAN    7698 28-SEP-81   1250   1400     30
      7698 BLAKE      MANAGER     7839 01-MAY-81   2850            30
      7782 CLARK      MANAGER     7839 09-JUN-81   2450            10
      7788 SCOTT      ANALYST     7566 09-DEC-82   3000            20
      7839 KING       PRESIDENT        17-NOV-81   5000            10
      7844 TURNER     SALESMAN    7698 08-SEP-81   1500      0     30
      7876 ADAMS      CLERK       7788 12-JAN-83   1100            20
      7900 JAMES      CLERK       7698 03-DEC-81    950            30
      7902 FORD       ANALYST     7566 03-DEC-81   3000            20
      7934 MILLER     CLERK       7782 23-JAN-82   1300            10
    14 rows selected.
    SQL>Given the example in the question, execute immediate wouldn't work, unless the table only had one row or bulk collect was used.

  • Execute an string as select statement

    Hi,
    I have a problem:
    I'm working with an older oracle verion (7.x??). I want to create a dynamic select statement. I create a string, e.g. v_sql_string, and want the database to execute it. What possibilities do I have to do this?
    Thanks in advance
    Mathias

    Yes,
    I went through the documentation, but it's only working with cursors.
    For better comprehension:
    This is the string:
    'select count(*) from invoice where sup_no ' || op_sup_no || ' v_sup_no and trpt_code ' || op_trpt_code || ' v_trpt_code and ship_no ' || op_ship_no || ' v_ship_no'
    I want to set the operators (op_xxx) dynamiclly. Isn't there something like RUN or EXECUTE, where I only have to pass a string, and the statement is executed ...
    But I don't know how ...
    Mathias

  • Concatination of string to select statement

    hi all,
    pl help me out.
    i want to concatenate string to select statement like
    create or replace procedure my_proc(p_sal number)
    as
    v_name varchar2(20);
    ssql varchar2(4000);
    begin
    ssql := ' ';
    select ssql || ' '|| select emp_name
    into v_name
    from employees
    where sal =p_sal;
    end;
    but it is giving error .
    pl correct it.
    thanks
    pavani

    Pavani,
    Still not clear.
    "Multiple conditions" sounds like you are trying to build predicates in the where clause, but in your example it looks like you are trying to build a select clause. Also your parameter is p_sal so the where clause "sal = p_sal" is fixed.
    The real question is WHY you want to "write multipul conditions"? WHY you want to "store it in a string .and then concatenate the string to next condition so on"?
    Regards,
    Rob.

  • SELECT statement comparing 2 fields in a table.

    Hi,
    Can someone help me out  in making a efficient SELECT statement for the follwing requirement.
    Say, I want to select all the records from a database table where the field, PLANT is equal to field SALESORG in the table (i.e., when both fields are equal select that record).
    Thanks & regards,
    Sree

    Hello,
    I think this is the answer to your question... if you explain a bit more we can formulate a query.
    Subquery
    Variants:
    1. ( select )
    2. ALL ( select )
    3. ANY ( select )
    4. SOME ( select )
    Effect
    A subquery is a SELECT statement select that occurs within a
    SELECT,
    OPEN CURSOR,
    UPDATE, or
    DELETE statement
    in the WHERE clause or HAVING clause, to check whether data from database tables or views meets certain criteria.
    Subqueries have a restricted syntax in comparison to the normal SELECT statement:
    SELECT result FROM source [WHERE where] [GROUP BY fields]       [HAVING having].
    Variant 1
    ( select )
    If the subquery returns a single value, you can use any relational operator except LIKE and BETWEEN.
    Example
    Selecting the flights with the most passengers:
    DATA: WA TYPE SFLIGHT.
    SELECT * FROM SFLIGHT
        INTO WA
        WHERE SEATSOCC = ( SELECT MAX( SEATSOCC ) FROM SFLIGHT ).
      WRITE: / WA-CARRID, WA-CONNID, WA-FLDATE.
    ENDSELECT.
    Note
    If you use a subquery with a relational operator instead of EXISTS, you may only specify one column in the SELECT clause. This can be either a field from the database table or an aggregate expression. Subqueries of this kind are referred to as scalar subqueries.
    Variant 2
    ALL ( select )
    If the subquery returns several lines, each containing one value, you specify that the comparison should apply for all of the values it returns.
    Example
    This example shows how to use ALL. It displays a list of the customer IDs of the customer (or customers) who have made the most bookings:
    DATA: ID TYPE SBOOK-CUSTOMID, CNT TYPE I.
    SELECT CUSTOMID COUNT( * ) AS C FROM SBOOK
        INTO (ID, CNT)
        GROUP BY CUSTOMID
        HAVING COUNT( * ) >=
          ALL ( SELECT COUNT( * ) FROM SBOOK GROUP BY CUSTOMID ).
      WRITE: / ID, CNT.
    ENDSELECT.
    Variant 3
    ANY ( select )
    Variant 4
    SOME ( select )
    If the subquery returns several lines each containing one value, this variant specifies that the comparison should apply to at least one of the values returned. The IN operator is the same as the combination = ANY.
    &ABAP_HINT
    If you use a subquery with the EXISTS operator, the expression is true if the subquery selects at least one line. You can useuse * in the SELECT clause of subqueries that use EXISTS.
    Example
    Selecting all flights from Frankfurt to New York between 1.1.1999 and 31.3.1999 that are not yet full:
    DATA: WA_SFLIGHT TYPE SFLIGHT.
    SELECT * FROM SFLIGHT AS F INTO WA_SFLIGHT
        WHERE SEATSOCC < F~SEATSMAX
          AND EXISTS ( SELECT * FROM SPFLI
                        WHERE CARRID = F~CARRID
                           AND CONNID = F~CONNID
                           AND CITYFROM = 'FRANKFURT'
                           AND CITYTO = 'NEW YORK' )
          AND FLDATE BETWEEN '19990101' AND '19990331'.
      WRITE: / WA_SFLIGHT-CARRID, WA_SFLIGHT-CONNID,
               WA_SFLIGHT-FLDATE.
    ENDSELECT.
    Subqueries such as the one in this example, in which the WHERE clause uses fields from the main query, are known as correlated subqueries. Subqueries can be nested, and a given subquery may contain any fields from other, hierarchically-superior subqueries.
    In a correlated subquery, the subquery is executed for each line r returned by the main query. In the above example, the main query finds all flights in table SFLIGHT that are not full and that have a date that meets the selection criterion. The statement then performs the subquery for each of the records returned by the main query, using the corresponding values of CARRID and CONNID, to check whether the relevant flight operates between Frankfurt and New York.
    Additional help
    Subqueries

  • Limitation on SQL executing select statement from ADO and Oracle 8.1.7.1 OleDB Driver

    Hi,
    we are running a query with a big dunamic select statement from VB code using ADO command object. When Execute method is called system hangs and control won't return back to the application. it seems to be that there is some type limitation on Query string length. Please tell us if there is any?
    we are running Oracle 8.1.7 Server on Windows 200 Server and connecting from a W2K professional, ADO 2.6 and Oracle OLEDB 8.1.7.1 OLEDB Driver.
    Sample code:
    Dim rs As ADODB.Recordset
    Dim cmd As ADODB.Command
    Set cmd = New Command
    With cmd
    .CommandText = ' some text with more than 2500 characters
    .CommandType = adCmdText
    Set rs = .Execute
    End With
    when i debug using VB6 and when .Execute line is called system hangs or return a message method <<somemethod> of <<some class name>> failed error.
    Any help is appreciated.
    Thanks,
    Anil

    A stored procedure would only slow you down here if it was poorly written. I suspect you want to use the translate function. I'm cutting & pasting examples from the documentation-- a search at tahiti.oracle.com will give you all the info you'll need.
    Examples
    The following statement translates a license number. All letters 'ABC...Z' are translated to 'X' and all digits '012 . . . 9' are translated to '9':
    SELECT TRANSLATE('2KRW229',
    '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
    '9999999999XXXXXXXXXXXXXXXXXXXXXXXXXX') "License"
    FROM DUAL;
    License
    9XXX999
    The following statement returns a license number with the characters removed and the digits remaining:
    SELECT TRANSLATE('2KRW229',
    '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789')
    "Translate example"
    FROM DUAL;
    Translate example
    2229
    Also, LIKE '%<string>%' is going to be rather expensive simply because it has to compare the entire string and because it forces full table scans, rather than using indexes. You could speed this sort of query up by using interMedia Text (Oracle Text now in 9i). If you can eliminate one of the '%' options, you could also improve things.
    My guess is that your stored procedure is inefficient and that's causing the problem-- 5k rows per table should be pretty trivial.
    If you post your query over on the PL/SQL forum, there are better performance tuners than I that might have more hints for you. To get really good advice, though, you'lllikely have to get at least the execution plan for this statement and may need to do some profiling to identify the problem areas.
    Justin

  • Usgent: using jsp date in sql select statement

    i have something like this:
    String day;
    String month;
    String year;
    select * from event where date = xxx
    where xxx is supposed to be obtained from the strings (day, month, year) and changed into a format that can be compared to in the select statement.
    what should xxx be?
    thks as lot cos i ahe been figuring out for very long.

    Use PreparedStatement and SimpleDateFormat:
    String year = "2002";
    String month = "9";
    String day = "12";
    String sDate = day + "/" + month + "/" + year;
    SimpleDateFormat df = new SimpleDateFormat("M/d/yyyy");
    Date dDate = df.parse(sDate);
    Connection con = DriverManager.getConnection(user, pw);
    PreparedStatement ps = con.prepareStatement("SELECT * FROM event WHERE date = ?");
    ps.setDate(1, dDate);
    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
    rs.close();
    ps.close();
    con.close();

  • Date equality in select statement

    Date equality in select statement giving 0 result even table contains record matching to it.please suggest what wrong in this query
    1- select *from  EOE_POC.PRODUCT_TEST_REPORT where CREATE_DATE = '03-SEP-13'
    2 - select *from  EOE_POC.PRODUCT_TEST_REPORT where CREATE_DATE >= '03-SEP-13'
    above query (2nd one) is giving 2 records.But I am intend to check for equality not greater ..plz enlighten

    Deekay wrote:
    Thanks Bhushan.
    select *from  EOE_POC.PRODUCT_TEST_REPORT where CREATE_DATE = sysdate
    can u plz throw some more light how to check by sysdate?
    Assuming CREATE_DATE is -- as it should be -- defined as a DATE (not a varchar) you need to be aware of the fact that DATEs always carry "time" as well.   So sysdate is not just "today", it is "this very second".    That's why you need to consider the use of TRUNC when you want to compare dates without consideration for the time.
    The other thing you need to be aware of is that the literal '03-SEP-13' is not a DATE, but a character string that humans would tend to recognize as representing a date.  But to a computer it is still just a character string, fundamentally no different from "here's yer sign!".  Therefore, in your usage of comparing the character string '03-SEP-13' to the DATE in CREATE_DATE, oracle has to to an implicit conversion.  And to do that implicit conversion it has to know what part of the character string represents the day, the month, the year, and possibly the hour, minute, and second.  To do this, it relies on the current setting of NLS_DATE_FORMAT, which may or may not be what you expect.    Please see: http://edstevensdba.wordpress.com/2011/04/07/nls_date_format/ - But I want to store my date as ...  for a more complete explanation.
    And finally, why are you using 2-digit years?  Are you actually working in IT and never heard of "the Y2K problem"?  Fifteen years ago I and thousands of my colleagues began a two-year grind of busting our butts to make sure systems continued to function correctly when the current date became 01-Jan-2000.  Please don't repeat the same mistakes that caused that problem.

  • How to utilize index in selection statement

    hi
    how to utilize index in selection statement and how is it reduces performance whether another alternative is there to reduce performance .
    thanks

    Hi Suresh,
    For each SQL statement, the database optimizer determines the strategy for accessing data records. Access can be with database indexes (index access), or without database indexes (full table scan).The cost-based database optimizer determines the access strategy on the basis of:
    *Conditions in the WHERE clause of the SQL statement
    *Database indexes of the table(s) affected
    *Selectivity of the table fields contained in the database indexes
    *Size of the table(s) affected
    *The table and index statistics supply information about the selectivity of table fields, the selectivity of combinations of table fields, and table size.     Before a database access is performed, the database optimizer cannot calculate the exact cost of a database access. It uses the information described above to estimate the cost of the database access.The optimization calculation is the amount by which the data blocks to be read (logical read accesses) can be reduced. Data blocks show the level of detail in which data is written to the hard disk or read from the hard disk.
    <b>Inroduction to Database Indexes</b>
    When you create a database table in the ABAP Dictionary, you must specify the combination of fields that enable an entry within the table to be clearly identified. Position these fields at the top of the table field list, and define them as key fields.
    After activating the table, an index is created (for Oracle, Informix, DB2) that consists of all key fields. This index is called a primary index. The primary index is unique by definition. As well as the primary index, you can define one or more secondary indexes for a table in the ABAP Dictionary, and create them on the database. Secondary indexes can be unique or non-unique. Index records and table records are organized in data blocks.
    If you dispatch an SQL statement from an ABAP program to the database, the program searches for the data records requested either in the database table itself (full table scan) or by using an index (index unique scan or index range scan). If all fields requested are found in the index using an index scan, the table records do not need to be accessed.
    A data block shows the level of detail in which data is written to the hard disk or read from the hard disk. Data blocks may contain multiple data records, but a single data record may be spread across several data blocks.
    Data blocks can be index blocks or table blocks. The database organizes the index blocks in the form of a multi-level B* tree. There is a single index block at root level, which contains pointers to the index blocks at branch level. The branch blocks contain either some of the index fields and pointers to index blocks at leaf level, or all index fields and a pointer to the table records organized in table blocks. The index blocks at leaf level contain all index fields and pointers to the table records from the table blocks.
    The pointer that identifies one or more table records has a specific name. It is called, for example, ROWID for Oracle databases. The ROWID consists of the number of the database file, the number of the table block, and the row number within the table block.
    The index records are stored in the index tree and sorted according to index field. This enables accelerated access using the index. The table records in the table blocks are not sorted.
    An index should not consist of too many fields. Having a few very selective fields increases the chance of reusability, and reduces the chance of the database optimizer selecting an unsuitable access path.
    <b>Index Unique Scan</b>
    If, for all fields in a unique index (primary index or unique secondary index), WHERE conditions are specified with '=' in the WHERE clause, the database optimizer selects the access strategy index unique scan.
    For the index unique scan access strategy, the database usually needs to read a maximum of four data blocks (three index blocks and one table block) to access the table record.
    <b><i>select * from VVBAK here vbeln = '00123' ......end select.</i></b>
    In the SELECT statement shown above, the table VVBAK is accessed. The fields MANDT and VBELN form the primary key, and are specified with '=' in the WHERE clause. The database optimizer therefore selects the index unique scan access strategy, and only needs to read four data blocks to find the table record requested.
    <b>Index Range Scan</b>
    <b><i>select * from VVBAP here vbeln = '00123' ......end select.</i></b>
    In the example above, not all fields in the primary index of the table VVBAP (key fields MANDT, VBELN, POSNR) are specified with '=' in the WHERE clause. The database optimizer checks a range of index records and deduces the table records from these index records. This access strategy is called an index range scan.
    To execute the SQL statement, the DBMS first reads a root block (1) and a branch block (2). The branch block contains pointers to two leaf blocks (3 and 4). In order to find the index records that fulfill the criteria in the WHERE clause of the SQL statement, the DBMS searches through these leaf blocks sequentially. The index records found point to the table records within the table blocks (5 and 6).
    If index records from different index blocks point to the same table block, this table block must be read more than once. In the example above, an index record from index block 3 and an index record from index block 4 point to table records in table block 5. This table block must therefore be read twice. In total, seven data blocks (four index blocks and three table blocks) are read.
    The index search string is determined by the concatenation of the WHERE conditions for the fields contained in the index. To ensure that as few index blocks as possible are checked, the index search string should be specified starting from the left, without placeholders ('_' or %). Because the index is stored and sorted according to the index fields, a connected range of index records can be checked, and fewer index blocks need to be read.
    All index blocks and table blocks read during an index range scan are stored in the data buffer at the top of a LRU (least recently used) list. This can lead to many other data blocks being forced out of the data buffer. Consequently, more physical read accesses become necessary when other SQL statements are executed
    <b>DB Indexex :Concatenation</b>
         In the concatenation access strategy, one index is reused. Therefore, various index search strings also exist. An index unique scan or an index range scan can be performed for the various index search strings. Duplicate entries in the results set are filtered out when the search results are concatenated.
    <i><b>Select * from vvbap where vbeln in ('00123', '00133', '00134').
    endselect.</b></i>
    In the SQL statement above, a WHERE condition with an IN operation is specified over field VBELN. The fields MANDT and VBELN are shown on the left of the primary index. Various index search strings are created, and an index range scan is performed over the primary index for each index search string. Finally, the result is concatenated.
    <b>Full Table Scan</b>
    <b><i>select * from vvbap where matnr = '00015'.
    endselect</i></b>
    If the database optimizer selects the full table scan access strategy, the table is read sequentially. Index blocks do not need to be read.
    For a full table scan, the read table blocks are added to the end of an LRU list. Therefore, no data blocks are forced out of the data buffer. As a result, in order to process a full table scan, comparatively little memory space is required within the data buffer.
    The full table scan access strategy is very effective if a large part of a table (for example, 5% of all table records) needs to be read. In the example above, a full table scan is more efficient than access using the primary index.
    <i><b>In Brief</b></i>
    <i>Index unique scan:</i> The index selected is unique (primary index or unique secondary index) and fully specified. One or no table record is returned. This type of access is very effective, because a maximum of four data blocks needs to be read.
    <i>Index range scan:</i> The index selected is unique or non-unique. For a non-unique index, this means that not all index fields are specified in the WHERE clause. A range of the index is read and checked. An index range scan may not be as effective as a full table scan. The table records returned can range from none to all.
    <i>Full table scan:</i> The whole table is read sequentially. Each table block is read once. Since no index is used, no index blocks are read. The table records returned can range from none to all.
    <i>Concatenation:</i> An index is used more than once. Various areas of the index are read and checked. To ensure that the application receives each table record only once, the search results are concatenated to eliminate duplicate entries. The table records returned can range from none to all.
    Regards,
    Balaji Reddy G
    ***Rewards if answers are helpful

  • Forcsing number formatting in Select statement

    Hi. I have a select statement that truncates a number field and compares it to a parameter, but it doesn't work in InfoView or as a scheduled report in Crystal Server.
    The string is :
    left(totext({gl_begbal.prd-yr-no}),4) startswith totext(year({?Pm-?Period Ending Date}))
    The number field is yyyymm, but Crystal Reports displays the field as 201,006, which causes the select statement to fail. When I  set Options, Fields, Number to whole number, CR displays it without the comma and the statement works perfectly. However, when I bring the report into CServer or fun it in InfoView, the report fails again, and I can't find any formatting options in either Server or InfoView settings.
    Is there a way to forcse the format to whole number within the select formulae?
    Thanks!
    Robin

    Post your question to the BOE Admin forum. Likely what is happening is the BOE server has a different default date format.

  • Retrieving multiple values from one column in SELECT statement

    Hi,
    I have a slight dilemma in that I'm trying to pull down all the values from a column from a select statement that includes some JOINS in it.
    If I run the query at the SQL Plus prompt, it pulls back all the values/rows.
    When I run the select (and prepared ) statement in my JSP, it only pulls back one of the 4 values I'm trying to retrieve.
    e.g.
    at the DB level :
    SELECT role_name, CC_ID FROM votetbl a
    INNER JOIN APPROVERS b ON
    a.BUSVP = b.BUSVP AND
    a.BRANCH = b.BRANCH
    WHERE CC_ID = 1688this will return:
    ROLE_NAME CC_ID
    ops 1688
    ops 1688
    comply 1688
    legal 1688
    comply 1688
    When run in my JSP, like so:
    String primID3a = request.getParameter("primID");
    Statement stmtovoter = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    String prepvotSQL = "SELECT role_name, CC_ID FROM votetbl a INNER JOIN APPROVERS b ON a.BUSVP = b.BUSVP AND " +
                         "a.BRANCH = b.BRANCH WHERE CC_ID = ?";
    PreparedStatement prepvotstmt = connection.prepareStatement(prepvotSQL);
    prepvotstmt.setString(1, primID3a);
    ResultSet rest3 = prepvotstmt.executeQuery();
    rest3.next();
    String votecat = rest3.getString(1);
    out.println("Vote category: "+votecat);I only get ops returned.
    Do I need to run an enumerator? Or reqest.getParameterValues or use a while statement around the results set?
    Any feedback and direction here is welcomed!
    Thanks!

    Actually, I tried looping and still only get 1, but returned several times.
    i.e.
    PreparedStatement prepvotstmt = connection.prepareStatement(prepvotSQL);
    prepvotstmt.setString(1, primID3a);
    ResultSet rest3 = prepvotstmt.executeQuery();
    rest3.next();
    String votecat = rest3.getString(1);
    while (rest3.next()) {
    out.print("category roles "+votecat);
    }then I get returned the following:
    admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admin
    like so.
    Where as at the DB level I get
    ROLE_NAME CC_ID
    admin 1688
    ops 1688
    ops 1688
    ops 1688
    ops 1688
    ops 1688
    ops 1688
    ops 1688
    risk 1688
    comply 1688
    legal 1688
    legal 1688
    ops 1688
    comply 1688
    Maybe the while should go around the getString(1) designation? But I was thinking I'd tried that and gotten invalid cursor error
    Something is definitely amiss, between the prepared statement in the servlet and the SELECT statement at the DB level.
    I can totally hardcode the statement in the servlet or JSP and it will return one value potentially several times, but only one.
    Other times, it will not return a value at all, even though one resides in the db.
    Yet go to the DB/SQL Plus prompt and it returns perfectly. I can simply copy and paste the SELECT statement from the out.print line I made and it works like a champ in SQL Plus. Any ideas why the same exact thing cannot return the proper values within the servlet/JSP?
    Yeeeeeeesh!!! : (
    Message was edited by:
    bpropes20

  • A trouble with "LIKE" in a select statement

    Hi!
    I'm having trouble with "LIKE" in a select statement...
    With Access I can make the following and everything works well:
    SELECT name, birthday
    FROM client
    WHERE birthday LIKE '*/02/*';
    but if try to do it in my application (it uses Access), it doesn't work - I just can't understand that!!!
    In my application the "month" is always the currently month taken from the "System". Look what I'm doing...
    String query1 = "SELECT name, birthday " +
              "FROM client " +
              "WHERE birthday " +
              "LIKE '*/" +
              pMonth +
              "/*' " +
              "ORDER BY birthday ASC ";
    ResultSet rs = statement1.executeQuery(consulta1);
    boolean moreRecords = rs.next();
    The variable "moreRecords" is always "false", the query returns nothing although the table "client" has records that attend the query.
    Please, anyone can help me?! It's a little bit urgent.
    Thanks,
    Katia.

    Hi Katia,
    I'll bet the problem lies with the characters you're using to escape the LIKE clause. You're using the ones that Access likes to see, but that's not necessarily what's built into the JDBC-ODBC driver class.
    You can find out what the correct escape wildcard characters are from the java.sql.DatabaseMetaData.getSearchStringEscape() method. It'll tell you what to use in the LIKE clause.
    I'm not 100% sure about your code. It doesn't use query1 anywhere. I'd do this:
    String query = "SELECT name, birthday FROM client WHERE birthday LIKE ? ORDER BY birthday ASC";
    PreparedStatement statement = connection.createStatement(query);
    String escape = connection.getMetaData().getSearchStringEscape();
    String test = escape + '/' + pMonth + '/' + escape;
    statement.setString(1, test);
    ResultSet rs = statement.executeQuery();
    while (rs.hasNext())
    // load your data into a data structure to pass back.
    rs.close();
    statement.close();Let me know if that works. - MOD

  • Using Select statement in IF condition?

    hi all,
    Can i use select statement in IF COndition in pl sql ?
    eg like- if( select 1 from ASD) then
    end if;

    There is no way to do any kind of select statement inside if conditions.
    Why don't test simple cases like this first?
    An example to show it.
    SQL> begin
      2   if exists (select 1 from dual) then
      3    dbms_output.put_line('ok');
      4   end if;
      5  end;
      6  /
    if exists (select 1 from dual) then
    ERRORE alla riga 2:
    ORA-06550: line 2, column 5:
    PLS-00204: function or pseudo-column 'EXISTS' may be used inside a SQL
    statement only
    ORA-06550: line 2, column 2:
    PL/SQL: Statement ignored
    SQL> begin
      2   if ( (select count(*) from dual) > 0 ) then
      3    dbms_output.put_line('ok');
      4   end if;
      5  end;
      6  /
    if ( (select count(*) from dual) > 0 ) then
    ERRORE alla riga 2:
    ORA-06550: line 2, column 8:
    PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
    ( - + case mod new not null others <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> avg
    count current exists max min prior sql stddev sum variance
    execute forall merge time timestamp interval date
    <a string literal with character set specification>
    <a number> <a single-quoted SQL string> pipe
    <an alternatively-quoted string literal with character set specification>
    <an alternativ
    ORA-06550: line 2, column 33:
    PLS-00103: Encountered the symbol ")" when expecting one of the following:
    . , @ ; for <an identifier>
    <a double-quoted delimited-identifier> group having intersect
    minus order partition start subpartition union where connect
    SQL> begin
      2   if ( 0 in (select count(*) from dual) ) then
      3    dbms_output.put_line('ok');
      4   end if;
      5  end;
      6  /
    if ( 0 in (select count(*) from dual) ) then
    ERRORE alla riga 2:
    ORA-06550: line 2, column 12:
    PLS-00405: subquery not allowed in this context
    ORA-06550: line 2, column 2:
    PL/SQL: Statement ignoredBye Alessandro

  • Select statement in if/else condition

    Hi i need to write a select statement in the if condition in pl/sql how can i write this
    example :
    if field_name not in (select statement) then
    Is this type of if condition is possible in pl/sql?
    thanks in advance for help.

    Qwerty wrote:
    here pick a job example salesman for ename ward, now i want to compare this job that is "salesman" with all the jobs which are before it. that is clerk in line 1 and salesman in line 2Define "before it". There is no order in relational tables. Only ORDER BY means ordered sets. Therefore there is no before/after without ORDER BY. Assuming ORDER BY empno, job count of same job title before empno:
    select  ename,
            job,
            count(*) over(partition by job order by empno) - 1 same_job_count_before_empno
      from  emp
    ENAME      JOB       SAME_JOB_COUNT_BEFORE_EMPNO
    SCOTT      ANALYST                             0
    FORD       ANALYST                             1
    SMITH      CLERK                               0
    ADAMS      CLERK                               1
    JAMES      CLERK                               2
    MILLER     CLERK                               3
    JONES      MANAGER                             0
    BLAKE      MANAGER                             1
    CLARK      MANAGER                             2
    KING       PRESIDENT                           0
    ALLEN      SALESMAN                            0
    ENAME      JOB       SAME_JOB_COUNT_BEFORE_EMPNO
    WARD       SALESMAN                            1
    MARTIN     SALESMAN                            2
    TURNER     SALESMAN                            3
    14 rows selected.To find job count of same job title as Ward has before Ward (by empno):
    SELECT  same_job_count_before_empno
      FROM  (
             select  ename,
                     count(*) over(partition by job order by empno) - 1 same_job_count_before_empno
               from  emp
      WHERE ename = 'WARD'
    SAME_JOB_COUNT_BEFORE_EMPNO
                              1SY.

Maybe you are looking for

  • Creating a variant transaction

    Hi, Im trying to create the above in SE93. Im calling it Z_SWWL and its calling transaction SWWL, which contains variants. But its not finding any 'transaction variant' to choose from!? Any ideas? Thanks, Dave

  • Self join vs Hierarchical Queries

    Hi, please tel me which one 1 should use ? i have to get simple manger's employ list, should i use self join or hierarchical queries(CONNECT BY and prior)? yours sincerely

  • HOW TO TURN OFF PANDORA MUSIC

    Everytime I try to watch a video with sound, music starts playing in the background on top of the sound from the video but I can't find where it's coming from. I was listening to internet radio and pandora yesterday but I closed the webpage.  I can't

  • OT? too many email sendings

    I have tried to set my options to only receive answers to my questions.  Yet in the last three days I have received in my personal email over 600 messages.   How can I limit messages to answers to my questions? Thanks

  • Problems with importing mp4 files into iTunes.

    Hi all, Since a few days I am the proud owner of an iPad 2. When I was looking for a solution to sync my video files (no problems with my pictures nor with my music files), I saw that I had to convert them from .avi to .mp4. Through this community I