Select records from MS Access tables using multiple conditions

Hi,
I am trying to build s select list of team names for a
sporting club website. The select list should include teams if the
currently logged in user is a coach, team manager, assistant coach,
player or a parent of a player.
When I have only one group of conditions in the where clause
it works fine. But that only accounts for one of the above roles.
As soon as I ad an OR and another set of criteria my CF7 server's
swsoc.exe goes into an permanent loop (well, at least 10 minutes, I
reboot after that :-)
For example, this works fine ...
<!--- select teams I coach, assistant coach, manage, am a
parent of a player, or am a player --->
<cfquery name="teams"
Datasource="#Application.Datasource#">
SELECT distinct teams.uid_team, team_name, uid_coach,
uid_team_manager, uid_coordinator, team_asst
from teams, player_agegroups, players
where
(player_agegroups.uid_team=teams.uid_team and
players.uid_user=player_agegroups.uid_user
and teams.uid_season=#session.season# and
players.uid_invoice_to=#session.userid#)
Order by team_name
</cfquery>
But as soon as I add another condition cf7 goes into a
loop...
<!--- select teams I coach, assistant coach, manage, am a
parent of a player, or am a player --->
<cfquery name="teams"
Datasource="#Application.Datasource#">
SELECT distinct teams.uid_team, team_name, uid_coach,
uid_team_manager, uid_coordinator, team_asst
from teams, player_agegroups, players
where
(player_agegroups.uid_team=teams.uid_team and
players.uid_user=player_agegroups.uid_user
and teams.uid_season=#session.season# and
players.uid_invoice_to=#session.userid#) or
(player_agegroups.uid_team=teams.uid_team and
players.uid_user=player_agegroups.uid_user
and teams.uid_season=#session.season# and
players.uid_user=#session.userid#) or
(player_agegroups.uid_team=teams.uid_team and
players.uid_user=player_agegroups.uid_user
and teams.uid_season=#session.season# and
teams_uid_coach=#session.userid#) or
(player_agegroups.uid_team=teams.uid_team and
players.uid_user=player_agegroups.uid_user
and teams.uid_season=#session.season# and
teams.team_asst=#session.userid#) or
(player_agegroups.uid_team=teams.uid_team and
players.uid_user=player_agegroups.uid_user
and teams.uid_season=#session.season# and
teams.uid_team_manager=#session.userid#)
Order by team_name
</cfquery>
Any combination hangs CF7, whether it be two, three or all
conditions, and any combination of conditions..
The teams table stores team name, coach, team manager,
assistant coach and coordinator. Players table stores the player
records, and the parent (uid_invoice_to), is part of the player
record. player agegroups has the teams, with a record for each
player in a team. The whole system is based around seasons, hence
the #session.season# variable.
What should happen is I get a very short list of teams. When
I select a team from the select list I then go and grab all the
player records from the player_agegroups table joined to the users
table to get their names, date of birth etc...
Can anyone see what I am doing wrong?
thanks
Tanya

You might try to change your query using a SQL JOIN command,
so you can link the appropriate tables independently from the WHERE
selection criteria. You could use Access to create the query and
then go to the SQL command view to get the correct synyax.

Similar Messages

  • Slecting records from MSAccess tables using multiple conditions

    Hi,
    I am trying to build s select list of team names for a
    sporting club website. The select list should include teams if the
    currently logged in user is a coach, team manager, assistant coach,
    player or a parent of a player.
    When I have only one group of conditions in the where clause
    it works fine. But that only accounts for one of the above roles.
    As soon as I ad an OR and another set of criteria my CF7 server's
    swsoc.exe goes into an permanent loop (well, at least 10 minutes, I
    reboot after that :-)
    For example, this works fine ...
    <!--- select teams I coach, assistant coach, manage, am a
    parent of a player, or am a player --->
    <cfquery name="teams"
    Datasource="#Application.Datasource#">
    SELECT distinct teams.uid_team, team_name, uid_coach,
    uid_team_manager, uid_coordinator, team_asst
    from teams, player_agegroups, players
    where
    (player_agegroups.uid_team=teams.uid_team and
    players.uid_user=player_agegroups.uid_user
    and teams.uid_season=#session.season# and
    players.uid_invoice_to=#session.userid#)
    Order by team_name
    </cfquery>
    But as soon as I add another condition cf7 goes into a
    loop...
    <!--- select teams I coach, assistant coach, manage, am a
    parent of a player, or am a player --->
    <cfquery name="teams"
    Datasource="#Application.Datasource#">
    SELECT distinct teams.uid_team, team_name, uid_coach,
    uid_team_manager, uid_coordinator, team_asst
    from teams, player_agegroups, players
    where
    (player_agegroups.uid_team=teams.uid_team and
    players.uid_user=player_agegroups.uid_user
    and teams.uid_season=#session.season# and
    players.uid_invoice_to=#session.userid#) or
    (player_agegroups.uid_team=teams.uid_team and
    players.uid_user=player_agegroups.uid_user
    and teams.uid_season=#session.season# and
    players.uid_user=#session.userid#) or
    (player_agegroups.uid_team=teams.uid_team and
    players.uid_user=player_agegroups.uid_user
    and teams.uid_season=#session.season# and
    teams_uid_coach=#session.userid#) or
    (player_agegroups.uid_team=teams.uid_team and
    players.uid_user=player_agegroups.uid_user
    and teams.uid_season=#session.season# and
    teams.team_asst=#session.userid#) or
    (player_agegroups.uid_team=teams.uid_team and
    players.uid_user=player_agegroups.uid_user
    and teams.uid_season=#session.season# and
    teams.uid_team_manager=#session.userid#)
    Order by team_name
    </cfquery>
    Any combination hangs CF7, whether it be two, three or all
    conditions, and any combination of conditions..
    The teams table stores team name, coach, team manager,
    assistant coach and coordinator. Players table stores the player
    records, and the parent (uid_invoice_to), is part of the player
    record. player agegroups has the teams, with a record for each
    player in a team. The whole system is based around seasons, hence
    the #session.season# variable.
    What should happen is I get a very short list of teams. When
    I select a team from the select list I then go and grab all the
    player records from the player_agegroups table joined to the users
    table to get their names, date of birth etc...
    Can anyone see what I am doing wrong?
    thanks
    Tanya

    Rustywater wrote:
    >
    > For example, this works fine ...
    >
    > <!--- select teams I coach, assistant coach, manage,
    am a parent of a player,
    > or am a player --->
    > <cfquery name="teams"
    Datasource="#Application.Datasource#">
    > SELECT distinct teams.uid_team, team_name, uid_coach,
    uid_team_manager,
    > uid_coordinator, team_asst
    > from teams, player_agegroups, players
    > where
    > (player_agegroups.uid_team=teams.uid_team and
    > players.uid_user=player_agegroups.uid_user
    > and teams.uid_season=#session.season# and
    > players.uid_invoice_to=#session.userid#)
    > Order by team_name
    > </cfquery>
    >
    > But as soon as I add another condition cf7 goes into a
    loop...
    >
    > <!--- select teams I coach, assistant coach, manage,
    am a parent of a player,
    > or am a player --->
    > <cfquery name="teams"
    Datasource="#Application.Datasource#">
    > SELECT distinct teams.uid_team, team_name, uid_coach,
    uid_team_manager,
    > uid_coordinator, team_asst
    > from teams, player_agegroups, players
    > where
    > (player_agegroups.uid_team=teams.uid_team and
    > players.uid_user=player_agegroups.uid_user
    > and teams.uid_season=#session.season# and
    > players.uid_invoice_to=#session.userid#) or
    > (player_agegroups.uid_team=teams.uid_team and
    > players.uid_user=player_agegroups.uid_user
    > and teams.uid_season=#session.season# and
    players.uid_user=#session.userid#) or
    > (player_agegroups.uid_team=teams.uid_team and
    > players.uid_user=player_agegroups.uid_user
    > and teams.uid_season=#session.season# and
    teams_uid_coach=#session.userid#) or
    > (player_agegroups.uid_team=teams.uid_team and
    > players.uid_user=player_agegroups.uid_user
    > and teams.uid_season=#session.season# and
    teams.team_asst=#session.userid#) or
    > (player_agegroups.uid_team=teams.uid_team and
    > players.uid_user=player_agegroups.uid_user
    > and teams.uid_season=#session.season# and
    > teams.uid_team_manager=#session.userid#)
    > Order by team_name
    > </cfquery>
    You are not just OR'ing your data filter, you are also OR'ing
    the
    relations between tables. You should define the relations
    between your
    tables in explicit JOIN statements in your FROM, and filter
    the data in
    your WHERE. You should also remove duplice filters in your
    WHERE
    statement. That would look something like:
    SELECT DISTINCT
    teams.uid_team,
    team_name,
    uid_coach,
    uid_team_manager,
    uid_coordinator,
    team_asst
    FROM
    (teams INNER JOIN
    player_agegroups ON
    player_agegroups.uid_team=teams.uid_team)
    INNER JOIN players ON
    players.uid_user=player_agegroups.uid_user
    WHERE
    teams.uid_season=#session.season#
    AND
    players.uid_invoice_to=#session.userid#
    OR
    players.uid_user=#session.userid#
    OR
    teams_uid_coach=#session.userid#
    OR
    teams.team_asst=#session.userid#
    OR
    teams.uid_team_manager=#session.userid#
    ORDER BY
    team_name
    Jochem
    Jochem van Dieten
    Adobe Community Expert for ColdFusion

  • Selecting record from a variable table

    Hi,
    I need to display the records from a table and the table name is saved in a variable. I am writing the code like
    create or replace procedure test_col as
         t_name VARCHAR2(40);
         V_ID VARCHAR2(10);
         cursor c_table is SELECT TABLE_NAME FROM ALL_TAB_COLS WHERE COLUMN_NAME = 'E_ID';
    begin
         OPEN C_TABLE;
         LOOP
              FETCH C_TABLE INTO T_NAME;
              EXIT WHEN C_TABLE%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE(T_NAME);
              SELECT E_ID INTO V_ID FROM T_NAME;
              DBMS_OUTPUT.PUT_LINE(V_ID);
         END LOOP;     
    CLOSE C_TABLE;
    end;
    Its giving the error as table name doesn't exist. Its taking t_name as the table name but i wan to use the value saved in that variable as the table name;
    Any help..
    Thanks
    Ashish

    CREATE OR REPLACE PROCEDURE test_col
    AS
       t_name   VARCHAR2 (40);
       v_id     VARCHAR2 (10);
       CURSOR c_table
       IS
          SELECT table_name
            FROM all_tab_cols
           WHERE column_name = 'E_ID';
    BEGIN
       OPEN c_table;
       LOOP
          FETCH c_table
           INTO t_name;
          EXIT WHEN c_table%NOTFOUND;
          DBMS_OUTPUT.put_line (t_name);
          EXECUTE IMMEDIATE 'SELECT e_id FROM ' || t_name
                       INTO v_id;
          DBMS_OUTPUT.put_line (v_id);
       END LOOP;
       CLOSE c_table;
    END;
    /

  • Selecting data from a RDBMS table using connector framework, JDBC-Connector

    Hi Experts,
    I'm trying to select data from a mysql database that is connected via the BI-JDBC System in the portal (EP 7 SP 11).
    The connection (using the Connector Gateway Service) is set up, but selecting data fails.
    Can you please give me a code example how to select data from a table using INativeQuery or IOperation / IExcecution ?? IQuery is depracted...
    Here my piece of code, actually method "connection.newNativeQuery()" throws exception "BICapabilityNotSupportedException: Operation is not supported":
         IConnection connection = null;
         public void connectToJDBCSystem(String jdbcSystem) {
           // open a connection
           try { // get the Connector Gateway Service
              Object connectorservice =
              PortalRuntime.getRuntimeResources().getService(IConnectorGatewayService.KEY);
              IConnectorGatewayService cgService =
              (IConnectorGatewayService) connectorservice;
              if (cgService == null) {
                   response.write("Error in get Connector Gateway Service <br>");
              try {
                ConnectionProperties prop =
                   new ConnectionProperties(request.getLocale(), request.getUser());
                connection = cgService.getConnection(jdbcSystem, prop);     
              } catch (Exception e) {
                   response.write("Connection to JDBC system " + jdbcSystem + " failed <br>");
                   response.write((String)e.getMessage() + "<br>");
                   e.printStackTrace();
              if (connection == null) {
                   response.write("No connection to JDBC system " + jdbcSystem + "<br>");
              } else {
                   response.write("Connection to JDBC system " + jdbcSystem + " successful <br>");
           } catch (Exception e) {
                response.write("Exception occurred <br>");
                           // up to this point it works fine...
           // build query using an IExecution object obtained from the Connection object
           response.write("prepare query 'SELECT idArt, art FROM art' <br>");
           String qstr = "SELECT idArt, art FROM art";
           INativeQuery query = null;
           try {
              query = connection.newNativeQuery();             
              response.write("execute query...<br>");
              ResultSet rs = (ResultSet)query.execute(qstr);
              while (rs.next()) {
                   response.write("<th>" + rs.getString(1) + "</th>");     
           } catch(Exception e)
              response.write("connection.newNativeQuery() failed <br>");
              response.write((String)e.getMessage() + "<br>");
              e.printStackTrace();
           } finally {
                 if( connection != null )
                 try {connection.close();}
                              catch(Exception ee){}
    Many thanks in advance, Monika
    Edited by: Monika Verwohlt on Jan 26, 2010 9:49 AM

    However this doesn't affect the XML encoding in data retrieved from XMLType using PL/SQL or programs (but it does work OK for SQLPlus SELECT).When performing an explicit serialization, with getClobVal method or XMLSerialize function, the database character set is used :
    NLS_LANG = FRENCH_FRANCE.WE8MSWIN1252
    NLS_CHARACTERSET = AL32UTF8
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL> create table test_nls of xmltype;
    Table créée.
    SQL> insert into test_nls values(xmltype('<?xml version="1.0" encoding="UTF-8"?><root/>'));
    1 ligne créée.
    SQL> select * from test_nls;
    SYS_NC_ROWINFO$
    <?xml version="1.0" encoding="WINDOWS-1252"?>
    <root/>
    SQL> select t.object_value.getclobval() from test_nls t;
    T.OBJECT_VALUE.GETCLOBVAL()
    <?xml version="1.0" encoding="UTF-8"?><root/>
    SQL> select xmlserialize(document object_value as clob) from test_nls;
    XMLSERIALIZE(DOCUMENTOBJECT_VALUEASCLOB)
    <?xml version="1.0" encoding="UTF-8"?><root/>

  • How can I select records from a DB table with intervals?

    Hello,
        Suppose my DB table is  having 20 lakh records. I need to fetch 50000(for eg, this number may change ) records intially then the next 50000 records and so on , so that I never get a runtime error "memory low".
    I can select the first 50000 records using "select up to " statement but once i select the first 50000 records how can i fetch the remainning records as parts.
    Please help.Urgent.
    Neeraj.

    Hi,
    Use packaze size statement in select statement.
    EX: This is syntax.
    SELECT ... INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE <itab> [PACKAGE SIZE <n>] ...
    1. If you want first 50000 records and do the required functionality with those and refresh the 50000 records and go for next 50000 means  use
    SELECT CARRID CONNID
    FROM   SPFLI
    INTO   CORRESPONDING FIELDS OF TABLE ITAB
          PACKAGE SIZE 50000.
    ENDSELECT.
    2. If you want to append all records means
    SELECT CARRID CONNID
    FROM   SPFLI
    INTO   APPENDING FIELDS OF TABLE ITAB
          PACKAGE SIZE 50000.
    ENDSELECT.
    Don't forghet to reward if useful....

  • How do I select rows from the same table that have multiple occurances

    Hi Everybody,
    I am trying to select records from a detail table by grouping it. The table has more than 1 million records and the query is not performing well. The basic question is how to select a distinct record from a table which matches all values in one column and any in the other.
    desc SCV
    ID NUMBER PK (ID + SCRID)
    SCRID NUMBER FK(SC)
    ID SCRID
    1 1
    2 1
    3 1
    4 2
    5 2
    6 3
    7 4
    8 4
    desc PROJECTS
    ID NUMBER PK
    NAME VARCHAR2(100)
    ID NAME
    1 PROJECT1
    2 PROJECT2
    3 PROJECT3
    4 PROJECT4
    desc PJS
    ID NUMBER
    PROID NUMBER FK (PROJECTS)
    SCRID NUMBER FK (SCV(SCRID + SCVID)
    SCVID NUMBER
    ID PROID SCRID SCVID
    1 1 1 1
    2 1 1 2
    3 1 2 5
    4 1 3 6
    5 1 4 7
    6 2 1 3
    7 2 2 4
    8 2 2 5
    9 2 4 7
    There are over 1 million records in PJS.
    desc TBP
    SCRID NUMBER
    SCVID NUMBER
    SCRID SCVID
    1 1
    1 2
    1 3
    2 4
    2 5
    3 6
    4 7
    4 8
    The requirement is to select projects that have matching SCRID, SCVID from TBP such that
    all distinct SCRID should match and within that and any SCVID match will do. (A "AND" between each SCRID and an "OR" for each SCVID in that SCRID like 'SCRID = 1 AND (SCVID = 1 OR SCVID = 2 OR SCVID = 3) AND SCRID = 2 AND (SCVID =....)
    So, for the sample data it should return us PROID = 1
    I have few queries written for this:
    SELECT PROID FROM PJS,TBP WHERE TBP.SCVID = PJS.SCVID AND TBP.SCRID = 1
    INTERSECT
    SELECT PROID FROM PJS,TBP WHERE TBP.SCVID = PJS.SCVID AND TBP.SCRID = 2
    INTERSECT
    SELECT PROID FROM PJS,TBP WHERE TBP.SCVID = PJS.SCVID AND TBP.SCRID = 3
    INTERSECT
    SELECT PROID FROM PJS,TBP WHERE TBP.SCVID = PJS.SCVID AND TBP.SCRID = 4
    This query performs well but the cost is very high, hardcoding, sorting.
    The 2nd option is to:
    SELECT pjs.PROID proid
    FROM TBP tbp,
    PJS pjs
    WHERE pjs.SCVID = tbp.SCVID
    AND pjs.SCRID = tbp.SCRID
    GROUP BY pjs.PROID
    HAVING COUNT(DISTINCT pjs.SCRID) = (SELECT COUNT(DISTINCT SCRID ) FROM TBP)
    This has a low cost but runs slowly.
    One more way I tried was with the IN operator like
    SELECT DISTINCT PROID FROM PJS A,TBP T WHERE T.SCRID = 1 AND T.SCVID = A.SCVID
    AND PROID IN (SELECT PROID FROM PJS A,TBP T WHERE T.SCRID = 2 AND T.SCVID = A.SCVID
    AND PROID IN (...SO ON with each DISTINCT SCRID.
    Again this involves too much of sorting.
    Any help will be appriciated.
    Thanks in advance.

    Hi Andrew,
    Use DELETE t_itab statement inside the loop.
    I have modified your code. It is perfectly working.See bellow  -
    LOOP AT it_zmember01 INTO wa_zmember01.
    WRITE: / wa_zmember01-mnumber UNDER 'NUMBER',
    wa_zmember01-mname UNDER 'NAME',
    wa_zmember01-mdob UNDER 'DOB'.
    WRITE / '-----------------------------------------------------------------'.
    DELETE it_zmember01.               " Modified
    ENDLOOP.
    DELETE it_zmember01. statement inside the loop will delete the current row of the table.
    Regards
    Pinaki

  • Selecting Records from 125 million record table to insert into smaller table

    Oracle 11g
    I have a large table of 125 million records - t3_universe.  This table never gets updated or altered once loaded,  but holds data that we receive from a lead company.
    I need to select records from this large table that fit certain demographic criteria and insert those into a smaller table - T3_Leads -  that will be updated with regard to when the lead is mailed and for other relevant information.
    My question is what is the best (fastest) approach to select records from this 125 million record table to insert into the smaller table.  I have tried a variety of things - views, materialized views, direct insert into smaller table...I think I am probably missing other approaches.
    My current attempt has been to create a View using the query that selects the records as shown below.  Then use a second query that inserts into T3_Leads from this View V_Market.  This is very slow. Can I just use an Insert Into T3_Leads with this query - it did not seem to work with the WITH clause?    My Index on the large table is t3_universe_composite and includes zip_code, address_key, household_key. 
    CREATE VIEW V_Market  as
    WITH got_pairs    AS  
         SELECT /*+ INDEX_FFS(t3_universe t3_universe_composite) */  l.zip_code, l.zip_plus_4, l.p1_givenname, l.surname, l.address, l.city, l.state, l.household_key, l.hh_type as l_hh_type, l.address_key, l.narrowband_income, l.p1_ms, l.p1_gender, l.p1_exact_age, l.p1_personkey, e.hh_type as filler_data, 1.p1_seq_no, l.p2_seq_no 
         ,      ROW_NUMBER () OVER ( PARTITION BY  l.address_key 
                                      ORDER BY      l.hh_verification_date  DESC 
                      ) AS r_num   
         FROM   t3_universe  e   
         JOIN   t3_universe  l  ON   
                l.address_key  = e.address_key
                AND l.zip_code = e.zip_code
              AND   l.p1_gender != e.p1_gender
                 AND   l.household_key != e.household_key         
                 AND  l.hh_verification_date  >= e.hh_verification_date 
      SELECT  * 
      FROM  got_pairs
      where l_hh_type !=1 and l_hh_type !=2 and filler_data != 1 and filler_data != 2 and zip_code in (select * from M_mansfield_02048) and p1_exact_age BETWEEN 25 and 70 and narrowband_income >= '8' and r_num = 1
    Then
    INSERT INTO T3_leads(zip, zip4, firstname, lastname, address, city, state, household_key, hh_type, address_key, income, relationship_status, gender, age, person_key, filler_data, p1_seq_no, p2_seq_no)
    select zip_code, zip_plus_4, p1_givenname, surname, address, city, state, household_key, l_hh_type, address_key, narrowband_income, p1_ms, p1_gender, p1_exact_age, p1_personkey, filler_data, p1_seq_no, p2_seq_no
    from V_Market;

    I had no trouble creating the view exactly as you posted it.  However, be careful here:
    and zip_code in (select * from M_mansfield_02048)
    You should name the column explicitly rather than select *.  (do you really have separate tables for different zip codes?)
    About the performance, it's hard to tell because you haven't posted anything we can use, like explain plans or traces but simply encapsulating your query into a view is not likely to make it any faster.
    Depending on the size of the subset of rows you're selecting, the /*+ INDEX hint may be doing your more harm than good.

  • Copying records from MS Access to Oracle ODBC

    I have a linked table from Oracle to an MS Access DB table. I am trying to "upsize" many records from the original MS Access DB table to one mirrored in Oracle.
    All is well save for the currency field in the original MS Access table. If I change the field to number or something from currency in Access, I will lose the formatting and potentially the data.
    I've tried several number combinations in the Oracle table but while I can copy and paste the records from the Access table to the linked Oracle table without getting any errors, when I query the records in the Oracle table it just shows pounds signs.
    Is there a certain number format in Oracle I should use for this?
    Is there a definitive way to make that work?
    I'll take any feedback I can get on this.
    Thanks.

    ok, this is still a bit insane. I copied all the records over, and in the MS Access ODBC linked part, I see the numbers correctly.
    After running various queries in Oracle, all are still showing #s unless it's a 0 value.
    i.e.
    SQL> SELECT LOAN_BALANCE FROM SEPTEMBERUPLOAD1A WHERE AUTOID < 30;
    LOAN_BALANCE
             .00
             .00
    29 rows selected.So then the question is, while I assume the data is in there potentially, and correct at that, is there a formatting trick I need to apply when querying the data through Oracle? Will people just see the pound signs? Let's say I'm later writing a Perl (yuck!) or Java (yeaaaah!) app on the web to view the data, will people see # signs? Or will they see double/decimal type figures?
    never mind....I guessed using the TO_CHAR function to retrieve it...I see that's what you do.
    SQL> SELECT TO_CHAR(LOAN_BALANCE) FROM SEPTEMBERUPLOAD1A WHERE AUTOID < 30;
    TO_CHAR(LOAN_BALANCE)
    0
    27786.16
    19864.43
    123670.56
    38820.51
    1417502.28
    101465.81
    90724.64
    127566.76
    62615.79
    74805.47
    17925.83
    122796.58
    103719.01
    72914.53
    169919.59
    33181.53
    0
    29623.22
    34192.74
    82956.63
    14387.6
    37506.27
    78149
    56214.33
    116728.95
    62696.78
    94718.46
    48605.89
    29 rows selected.Thanks!
    Message was edited by:
    user515689
    Message was edited by:
    user515689

  • How to select first several records from a database table by using select?

    Hi,
       I want to select first 100 records from a database table by using select clause. How to write it?
       Thanks a lot!

    hai long!
                 well select statement is used to retrive
    records from the database.
    following is the syntax to be used.
    1) select *  into corresponding fields of itab from basetable where condition.
    endselect.
      ex: select * into corresponding fields of itab from mara
                where matnr >= '1' and  matnr <= '100'.
           append itab.
          endselect.
    select * is a loop statement.it will execute till matnr is less than or equal to 100.
    note: you can also mention the required field names in the select statement otherwise it will select all the field from table mara.
    note: itab means your internal table name.
    hope you got the required thing.if it really solved u r problem then award me the suitable points.<b></b>

  • Error while retrieving data from PL/SQL Table using SELECT st. (Urgent!!!)

    Hi Friends,
    I am using Oracle 8.1.6 Server, & facing problems while retrieving data from a PL/SQL Table:
    CREATE or REPLACE PROCEDURE test_proc IS
    TYPE tP2 is TABLE of varchar2(10); --declared a collection
    dt2 tP2 := tP2('a','b','c');
    i NUMBER(8);
    begin
    SELECT COUNT(*) INTO i FROM TABLE(CAST(dt2 as tP2));
    DBMS_OUTPUT.PUT_LINE('**'||i);
    end;
    While executing the above procedure, I encountered foll. error:
    ERROR at line 1:
    ORA-00600: internal error code, arguments: [15419], [severe error during PL/SQL execution], [], [],
    ORA-06544: PL/SQL: internal error, arguments: [pfrrun.c:pfrbnd1()], [], [], [], [], [], [], []
    ORA-06553: PLS-801: internal error [0]
    Can anyone please help me, where the problem is??
    Is it Possible to retrieve data from PL/SQL TABLE using SELECT statement? & How ?
    Thanks in advance.
    Best Regards,
    Jay Raval.

    Thanks Roger for the Update.
    It means that have to first CREATE TYPE .. TABLE in database then only I can fire a Select statement on that TYPE.
    Actually I wanted to fire a Select statement on the TABLE TYPE, defined & declared in PLSQL stored procedure using DECLARE TYPE .. TABLE & not using CREATE TYPE .. TABLE.
    I was eager to know this, because my organization is reluctant in using CREATE TYPE .. TABLE defined in the database, so I was looking out for another alternative to access PL/SQL TABLE using Select statement without defining it database. It would have been good if I could access a PLSQL TABLE using Select statement Declared locally in the stored procedure.
    Can I summarize that to access a PL/SQL TABLE using SELECT statement, I have to first CREATE TYPE .. TABLE?
    If someone have any other idea on this, please do let me know.
    Thanks a lot for all help.
    Best Regards,
    Jay Raval.
    You have to define a database type...
    create type tP2 is table of varchar2(10)
    CREATE OR REPLACE PROCEDURE TEST_PROC
    IS
    dt2 tP2 := tP2('a','b','c');
    i NUMBER(8);
    begin
    SELECT COUNT(*) INTO i FROM TABLE(CAST (dt2 AS tP2));
    DBMS_OUTPUT.PUT_LINE('**'||i);
    end;
    This will work.
    Roger

  • Can i select Records from two tables into an itab.

    Hi,
        Suppose that i have two tables spfli and sflight.
        Now i want the records from both the tables into a single internal table.
        If so please let me know how this can be done.
        itab should consist of all the columns in sflight and spfli.
    Regards,
    Sai

    Sai,
    Yes u can do it using JOINs.
    Use this link for ref
    http://www.sap-img.com/abap/inner-joins.htm
    INNER JOIN results are an intersection of the tables being joined where in only if both the tables havethe data the result is pused onto the result set.
    WHERE as in LEFT OUTR JOIN you can push the data of the LEF T table on the resultset even when the join condition is not met.
    The use is that you wantto have all the data that is there in left table and also the right table if the join condition is a success then right table fileds will have data else they are initial.
    OUTJOIN's are used in MAINTENANNCE VIEWS, HELP VIEWS .
    INNER JOINS are used DATABSE VIEWS.
    Inner Join:-
    SELECT pcarrid pconnid ffldate bbookid
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM ( ( spfli AS p
    INNER JOIN sflight AS f ON pcarrid = fcarrid AND
    pconnid = fconnid )
    INNER JOIN sbook AS b ON bcarrid = fcarrid AND
    bconnid = fconnid AND
    bfldate = ffldate )
    WHERE p~cityfrom = 'FRANKFURT' AND
    p~cityto = 'NEW YORK' AND
    fseatsmax > fseatsocc.
    Left Outer Join
    SELECT scarrid scarrname p~connid
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM scarr AS s
    LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid AND
    p~cityfrom = 'FRANKFURT'.
    Reward if helpful,
    Karthik

  • Select record from database table

    how to select a record from data-base table for current month in module-pool, i.e if current month is august then records selected should between 1/08/10 to 31/08/10.
    And, i also want to select records for last month i.e if current month is august then records selected should be between 1/07/10 to 31/07/10.
    And one thing more, it should work for every scenario. Like for months are changing then it should work according to that.
    Example: If month changes to October then current month ll be October and last month ll become September.
    Plz help me out.
    Moderator message: you chose a better forum this time, but the question is still too basic to be asked here, please (re)search yourself first, these forums are not catering to beginners.
    locked by: Thomas Zloch on Aug 8, 2010 9:41 PM

    Hi Nishant,
    You can use the option <b>ORDER BY </b> in your SELECT clause.
    This is the SAP Documentation for <b>ORDER BY </b> option.
    <i>Variant 1</i>
    <b>...ORDER BY PRIMARY KEY</b>
    <b>Effect</b>
    Sorts the selected lines in ascending order by the primary key of the database table. This variant is only permitted for SELECT * ....
    <i>Notes</i>
    Since views do not have a primary key, specifying ORDER BY PRIMARY KEY only makes sense with database tables. If, however, you do specify ORDER BY PRIMARY KEY with a view, all fields of the view are sorted in ascending order.
    <i>Variant 2</i>
    <b>ORDER BY f1 ... fn</b>
    <i>Effect</i>
    Sorts the selected records in ascending order by the specified column references f1 ... fn. If a list is also specified in the SELECT clause, the column references f1, ..., fn must appear in this list.
    By supplementing the statement with DESCENDING, you can sort in descending order using any of the fields f1, ..., fn.
    The default sort sequence is ascending order, but you can make this explicit by adding the addition ASCENDING.
    Consider this code this will select the latest 10 records form DB table(Note can use <b>Variant 2</b> for DB tables also.
    REPORT zarun_1.
    DATA : it_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE.
    START-OF-SELECTION.
      SELECT * FROM mara
                INTO TABLE it_mara
                <b>UP TO 10 ROWS                "No of rows you need(give 1 here)
               ORDER BY matnr DESCENDING.    "Specify the Key Fields here.</b>
      LOOP AT it_mara.
        WRITE : / it_mara-matnr,
                  it_mara-mtart.
      ENDLOOP.
    Regards,
    Arun Sambargi.
    Message was edited by: Arun Sambargi

  • Selecting the last record from a database table

    In my ABAP Program, I have to use a select statement to retrieve the last record from the database table with the same key.  In other words, the Program will get more than one hit on the database table for the selected keys and I need to retrieve values from only the last record and not the first.  I know I can use an internal table to sort the records first and then retrieve the right value.   But to make things easier, is there a SELECT statement keyword than I can use to do this in one single step?  Thanks!

    hi,
    tables:mara.
        data: begin of it_mara occurs 0,
                matnr like mara-matnr,
                meins like mara-meins,
                mtart like mara-mtart,
                end of it_mara.
    select-options:s_matnr for mara-matnr.
    select matnr
              meins
              mtart
    from mara
    into table it_mara
    where matnr in s_matnr.
    if not it_mara[] is initial.
    sort it_mara by matnr descending.
    read table it_mara index 1.
    endif.
    then you get the last record of the select statement.
    reward points if useful,
    venkat.

  • I HAVE A SOURCE TABLE WITH 10 RECORDS AND TARGET TABLE 15 RECORDS. MY WUESTION IS USING WITH THE TABLE COMPARISON TRANSFORM I WANT TO DELETE UNMATCHED RECORDS FROM THE TARGET TABLE ??

    I HAVE A SOURCE TABLE WITH 10 RECORDS AND TARGET TABLE 15 RECORDS. MY QUESTION IS USING WITH THE TABLE COMPARISON TRANSFORM .I WANT TO DELETE UNMATCHED RECORDS FROM THE TARGET TABLE ?? HOW IT IS ??

    Hi Kishore,
    First identify deleted records by selecting "Detect deleted rows from comparison table" feature in Table Comparison
    Then Use Map Operation with Input row type as "delete" and output row type as "delete" to delete records from target table.

  • Performance problem with selecting records from BSEG and KONV

    Hi,
    I am having performance problem while  selecting records from BSEG and KONV table. As these two tables have large amount of data , they are taking lot of time . Can anyone help me in improving the performance . Thanks in advance .
    Regards,
    Prashant

    Hi,
    Some steps to improve performance
    SOME STEPS USED TO IMPROVE UR PERFORMANCE:
    1. Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.
    2. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.
    3. Design your Query to Use as much index fields as possible from left to right in your WHERE statement
    4. Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.
    5. Avoid using nested SELECT statement SELECT within LOOPs.
    6. Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.
    7. Avoid using SELECT * and Select only the required fields from the table.
    8. Avoid nested loops when working with large internal tables.
    9. Use assign instead of into in LOOPs for table types with large work areas
    10. When in doubt call transaction SE30 and use the examples and check your code
    11. Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search. This is a general thumb rule but typically if you are sure that the data in internal table is less than 200 entries you need not do SORT and use BINARY SEARCH since this is an overhead in performance.
    12. Use "CHECK" instead of IF/ENDIF whenever possible.
    13. Use "CASE" instead of IF/ENDIF whenever possible.
    14. Use "MOVE" with individual variable/field moves instead of "MOVE-
    CORRESPONDING" creates more coding but is more effcient.

Maybe you are looking for

  • [SOLVED]Can't get Orage to work in Openbox

    Put simply, nothing happens. orage ** Message: Orage **: Too small icon size, using static icon if I try that again, with orage still running, I get this (orage:6523): Gdk-CRITICAL **: gdk_x11_get_server_time: assertion `GDK_IS_WINDOW (window)' faile

  • OLE for transfer data to excel

    Hi Can any one send me the coding to use ole for sending data from a multirecord form to excel? I have never used OLE. i am using DDE package for this task but its very slow. regards, adeel

  • Determination of price conditions

    Hi all !! We have a problem with our price determination. The situation that is working wrong is the following: When we create a sales order which is giong to be delivered in several steps (For instance, 400 units of the material XXXX, delivering 100

  • I have CS5.1 on my PC and I want to install a 2nd copy onto my MacBook. Can I do that?

    I just downloaded the software from my Adobe Account list but when I get to where they ask for the serial number it tells me the serial number is not valid for this product. Please help! I'm having issues with my PC and I'd feel a lot more comfortabl

  • I want to click on text of radioButton....

    I inserted a htmlb:readioButtonGroup into my Application. I noticed that the radioButton can only be activated by clicking on the button itself, not by clicking on the text. Is there any way to enable this? <htmlb:radioButtonGroup id   = "rbgrp">   <