Selecting Randoms from Query of Queries

I can create a query that selects random records
<cfquery....>
select top 10 * from table order by newid() <!--- SQL
Server --->
</cfquery>
or
<cfquery....>
select top 10 * from table order by rand() limit 10 <!---
MySQL--->
</cfquery>
However, is there a way to cache a query then select random
records from it?
I want to cache the overall query that retrieves all the
records, then
randomly pull
from that cached query.
If I use newid() or rand(), the query bombs on the
parentheses.
Any suggestions?
Tami

well, it's not really a query of queries... more like a query
of a cached
query :)
"DixieGal" <[email protected]> wrote
in message
news:ffsn1b$***$[email protected]..
|I can create a query that selects random records
| <cfquery....>
| select top 10 * from table order by newid() <!--- SQL
Server --->
| </cfquery>
|
| or
| <cfquery....>
| select top 10 * from table order by rand() limit 10
<!--- MySQL--->
| </cfquery>
|
| However, is there a way to cache a query then select random
records from
it?
| I want to cache the overall query that retrieves all the
records, then
| randomly pull
| from that cached query.
|
| If I use newid() or rand(), the query bombs on the
parentheses.
|
| Any suggestions?
|
| --
|
| Tami
|
|

Similar Messages

  • Display select list from query on manual tabular form

    Hello,
    I'm trying to display a select list from query on a manual tabular form. I'm using a collection to store the data. I can't seem to get the query to work. I can display the item as a text item. Any help would be appreciated. Thanks, Elizabeth.
    SELECT
    -- Notice how I'm keeping the idx value the same as the column value in the collection. This helps to keep things organized
    -- I also apply an id to each entry
    -- I append the error value to the empname and sal
    -- The Seq_id. Usefull when hiding rows (for delete) and then submitting from
    apex_item.hidden(1,x.seq_id, null, x.seq_id || '_seq_id') ||
    -- The Primary Key of the column
    apex_item.hidden(2, x.ceah_people_id, null, x.seq_id || '_ceah_people_id') || x.ceah_people_id ceah_people_id,
    -- Employee Name
    case when x.seq_id = -1
    then
    apex_item.select_list_from_query (3,
    NULL,
    'select distinct language_name d, '
    || 'language_id r from foreign_language',
    'style="width:170px" ' ,
    'YES',
    '0',
    '- Select Language -',
    'x.seq_id_' || LPAD (9900 + LEVEL, 4, '0'),
    NULL,
    'NO'
    else
    apex_item.text (3,(select language_name from foreign_language where x.language_id = foreign_language.language_id),
    80,
    100,
    'style="width:170px" readonly="readonly"',
    'f32_' || LPAD (ROWNUM, 4, '0')
    end
    || err.language_id language_id,
    /* apex_item.text(3,x.language_id,null, null, null, x.seq_id || '_language_id') || err.language_id language_id,
    -- Employee Salary
    apex_item.text(4,x.proficiency, null, null, null, x.seq_id || '_proficiency') || err.proficiency ||
    -- Store the sql action type as well.
    apex_item.hidden(50,x.sql_action_typ, null, x.seq_id || '_sql_action_typ_id') proficiency,
    -- Last but not least the row error
    err.row_error
    FROM (SELECT ac.c001 seq_id,
    ac.c002 ceah_people_id,
    ac.c003 language_id,
    ac.c004 proficiency,
    ac.c049 modifiable_flag,
    ac.c050 sql_action_typ
    FROM apex_collections ac
    WHERE ac.collection_name = 'DATA_COLLECTION'
    ORDER BY ac.seq_id) x,
    -- Error Collection
    (SELECT ac.seq_id seq_id,
    ac.c002 ceah_people_id,
    ac.c003 language_id,
    ac.c004 proficiency,
    ac.c050 row_error -- Useful when individual data is correct, however the row of data is not. Ex: start/end dates
    FROM apex_collections ac
    WHERE ac.collection_name = 'ERROR_COLLECTION'
    ORDER BY ac.seq_id) err
    WHERE x.seq_id = err.seq_id(+)

    I got so frustrated I started over. I'm following the how to create a manual form.
    http://www.oracle.com/technology/products/database/application_express/howtos/tabular_form.html#MANUAL
    The problem I'm now having is even though I display items as hidden, there is a column holder on the report for them. If I go into the report attributes and toggle the show attribute off I cannot reference an items value in my logic. I used /&nbsp/ for the column heading but I still get the little sort arrow where the column heading should be. I tried to toggle the sort attribute off but the sort arrow still shows up. How can I use the apex_item.hidden and not get a place holder for the column on a report? Thanks, Elizabeth
    Here is the code I'm using to generate the report:
    select x.ceah_people_lang_id,
    x.language_id,
    x.proficiency,
    x.ceah_people_id
    from (
    select apex_item.hidden(1,ceah_people_lang_id) ceah_people_lang_id,
    apex_item.select_list_from_query(2,language_id,'select language_name, language_id from foreign_language') language_id,
    apex_item.select_list_from_query(3,proficiency,'select name, id from proficiency') proficiency,
    apex_item.hidden(4,ceah_people_id) ceah_people_id
    from ceah_people_language where ceah_people_language.ceah_people_id = :P152_person_id
    union all
    select apex_item.hidden(1,null) ceah_people_lang_id,
    apex_item.select_list_from_query(2,null,'select language_name, language_id from foreign_language') language_id,
    apex_item.select_list_from_query(3,null,'select name, id from proficiency') proficiency,
    apex_item.hidden(4,null) ceah_people_id
    from dual) x

  • Select list from query in report

    Hello everybody,
    I want to include a select list from a query in a report's colomn, but the select list should only be displayed conditionally. I wanted to do this with the help of "case when" in the corresponding SQL statement.
    The select list itsself works, but when I combine it with "case when" I always get the error message:
    ORA-01427: single-row subquery returns more than one row
    The select statement is as following:
    select
    htmldb_item.checkbox(1,rownum) " ",
    x.idee,
    x.stunden_ilp,
    x.stunden_ild,
    x.stunden_ilm,
    x.stunden_ief,
    x.stunden_ir,
    x.pe_id,
    x.l_art_id,
    x.version_id
    from (
    select
    (select case
    when (select name from cn_pl_projektidee s01
    where s01.idee_id = '2') IS NULL then
    (select distinct htmldb_item.select_list_from_query(5,name,'select distinct name from cn_pl_projektidee') name from cn_pl_projektidee s01
    where s01.idee_id = t1.idee_id)
    else
    (select distinct htmldb_item.text(5,name) name from cn_pl_projektidee s01
    where  s01.idee_id = t1.idee_id)
    END from cn_pl_std_peplanung t1) Idee,
    from cn_pl_std_peplanung t1, cn_pl_projektelemente z1, cn_pl_version u1, cn_pl_projektidee s1
    where t1.version_id = '&P6_VERSION_WAHL.'
    and t1.pe_id ='&P6_HELP_PRODET.' 
    and t1.l_art_id ='&P6_L_ART_ID.'
    group by t1.pe_id, t1.version_id, t1.idee_id, t1.l_art_id) x
    order by x.ideeDoes anybody know what could be the problem or what other solutions I could try??
    Greetings!
    Patrick

    Found 2 ways to solve it:
    *1. dynamic action (JQuery)*
    $("#f20_1234 option[value=13]").attr('selected', 'selected');
    *2. process*
    BEGIN
    HTP.p('<script type="text/javascript">');
    --HTP.p('problem()');
    HTP.p('html_SetSelectValue(''f20_903'',188)');
    HTP.p('html_SetSelectValue(''f20_903'',189)');
    HTP.p('</script>');
    END;

  • PL/SQL select list from query

    Hello,
    I am trying to modifying a PL/SQL process. Wherever there was a reference to the Application ID, I wanted to change it to refer to the Application Alias.
    Here is the original code:
    declare
       cursor app_cur is
          select aa.application_id||' - '||aa.application_name app_name,
                 aa.application_id
            from apex_applications aa
           where exists (select 1
                           from profiles p
                          where p.application_id = aa.application_id);
       cursor user_app_cur (p_user number, p_app number) is
          select to_char(profile_id)
            from user_app_profiles
           where user_id = p_user
             and application_id = p_app;
       v_profile   varchar2(10);
       v_count     number := 0;
       v_class     varchar2(15);
    begin
       htp.p('<table class="t3standardalternatingrowcolors" cellpadding="0" cellspacing="0">');
       htp.p('<tr><th class="t3header" >Application</th><th class="t3header" >Profile</th></tr>');
       for app in app_cur loop
          v_count := v_count + 1;
          if mod(v_count,2) = 1 then
             v_class := 't3dataalt';
          else
             v_class := 't3data';
          end if;
          open  user_app_cur(:P3_USER_ID, app.application_id);
          fetch user_app_cur
           into v_profile;
          if user_app_cur%notfound then
             v_profile := 'NONE';
          end if;
          close user_app_cur;
          htp.p('<tr><td class="'||v_class||'">'||app.app_name||
                '</td><td class="'||v_class||'">'||
                apex_item.select_list_from_query(40, v_profile,
                  'select description, profile_id from profiles where application_id = '||app.application_id,
               null, 'YES', 'NONE', 'No Profile Assigned', null, null, 'NO')||
                apex_item.hidden(41,app.application_id) ||
              '</td></tr>');
       end loop;
       htp.p('</table>');
    end;Here is my revised code:
    declare
       cursor app_cur is
          select aa.alias||' - '||aa.application_name app_name,
                 aa.alias
            from apex_applications aa
           where exists (select 1
                           from profiles p
                          where p.application_alias = aa.alias);
       cursor user_app_cur (p_user number, p_app varchar2) is
          select to_char(profile_id)
            from user_app_profiles
           where user_id = p_user
             and application_alias = p_app;
       v_profile   varchar2(10);
       v_count     number := 0;
       v_class     varchar2(15);
    begin
       htp.p('<table class="t3standardalternatingrowcolors" cellpadding="0" cellspacing="0">');
       htp.p('<tr><th class="t3header" >Application</th><th class="t3header" >Profile</th></tr>');
       for app in app_cur loop
          v_count := v_count + 1;
          if mod(v_count,2) = 1 then
             v_class := 't3dataalt';
          else
             v_class := 't3data';
          end if;
          open  user_app_cur(:P3_USER_ID, app.alias);
          fetch user_app_cur
           into v_profile;
          if user_app_cur%notfound then
             v_profile := 'NONE';
          end if;
          close user_app_cur;
          htp.p('<tr><td class="'||v_class||'">'||app.app_name||
                '</td><td class="'||v_class||'">'||
                apex_item.select_list_from_query(40, v_profile,
                  'select description, profile_id from profiles where application_alias = '||app.alias,
               null, 'YES', 'NONE', 'No Profile Assigned', null, null, 'NO')||
                apex_item.hidden(41,app.alias) ||
              '</td></tr>');
       end loop;
       htp.p('</table>');
    end;Here is the error:
    ORA-06550: line 1, column 153: PL/SQL: ORA-00904: "F109NEWNAME": invalid identifier ORA-06550: line 1, column 7: PL/SQL: SQL Statement ignored
    I think that the problem is in the table/LOV generation near the end, but I don't fully understand the apex_item.select_list_from_query function as it is written (I didn't write it).
    Any help is greatly appreciated.
    Thanks,
    Matt

    Hi Matt,
    This line:
    'select description, profile_id from profiles where application_alias = '||app.aliaswould become:
    select description, profile_id from profiles where application_alias = F109NEWNAMEif F109NEWNAME was the app_alias. SQL would see F109NEWNAME as a variable as it is not in quotes. Therefore, you should change the line to:
    'select description, profile_id from profiles where application_alias = ''' || app.alias || ''''to end up with:
    select description, profile_id from profiles where application_alias = 'F109NEWNAME'which would make more sense
    Andy

  • How to select Variable from Drop Down Queries - WAD 7.0

    Hello All,
    I've scenario where users will click on link and should see the default data of Daily and also have drop down box in the same web template where Weekly, Monthly, Quarterly and others must be displayed so that user can switch back & forth between views.
    my Monthly, Quarterly & others are views out of a Query however my daily & weekly are separate queries where variables are populated, so that user can enter desired number of days or weeks that he/she wants to see data for.
    <b>Question:</b>: when I use drop down to switch from monthly to daily or weekly I'm not seeing the variable which should populate so that user can enter number of days/weeks.
    Please let me know if there is a solution for this - Thanks in advance!!!!..
    Peja

    Hi,
    Try checking the data you are viewing in the drop down box. It may help to look at posted values instead of master data (or vice versa). Try changing that and see if it makes a difference. Also, are your variables navigational? If not, they will act as filters and you won't be able to change when you run. Check these settings and hopefully they will give some direction.
    Cheers,
    Rusty

  • A select list from query question

    Hello all - I've looked in detail at a great deal of posts on this subject and believe what I am trying to achieve is not unusual or out of scope. Therefore it's likely me mis-interpreting something and I'd be grateful for anybody's input.
    I have the following as a column in a report
    apex.select_list_from_query( 21,
              a.reserved_by,
              'select g.user_name,g.user_id
              from users g, user_roles h
         where g.user_id=h.user_id and h.role_id in (2,3)'
         , null ,
         'YES',
         '-1',
         '- Not Reserved -') slov1 ,
    If 'reserved_by' is null, I want '- Not Reserved -' to appear in the select list, otherwise I want the value in user_name. Where reserved_by is not null, I get the appropriate user_name returning the appropriate user_id. Where reserved_by is null, I get null returning null in the select list.
    '- Not Reserved -' which is the value I've tried to assign to p_null_text, also appears in the select list and returns '-1' . However '-Not Reserved-' only appears as an extra option, rather than becoming the display value for reserved by=null.
    So, if the values in reserved_by are 'user1','user2' and null and the P_query returns
    'user1',1
    'user2',2
    'user3',3
    my select list for the row having reserved_by=NULL looks like
    user1
    user2
    user3
    - Not Reserved -
    NULL (ie blank).
    Following a suggestion in a thread from 2005(!), I changed the p_query to
    'select g.user_name,g.user_id
    from users g, user_roles h
    where g.user_id=h.user_id
    and h.role_id in (2,3) union ALL
    SELECT ''- Not Reserved -'' user_name, 0 user_id from dual',
    null, NO'
    and set p_show_null to 'NO'. This achieves the functionality I want. So perhaps, though I can't figure out what I was doing wrong with the 'correct' usage. Anyway, I'll post this in case it proves useful to others!
    Toby

    Hi Apex Experts,
    can some one suggest me an alternate way to achieving this. I really have no idea on how to take this forward. :(
    Any help/pointers will be highly appreciated.
    Thanks,
    Satya.
    Edited by: Chaitu_Apex on May 13, 2010 3:50 AM

  • Selecting random from hashtable

    Hi,
    I need a datastructure in which I can store pairs of IP numbers and port numbers. This database might get pretty big (it's like a p2p application). A hashtable seems like a good choice. This way I can quickly check if a certain IP number is in the database.
    But I also need to get a random entry from the database. Is there a nice and easy way to do this? Or should I opt for another datastructure ?
    thanks in advance,

    Thanks for the reactions.
    My concern with these methods is that if I have a large database they will require a lot of extra memory. It will have to work for a database of a couple of thousands entries. That's purely theoretical, but scalability is a key point here.
    Alex's solution clearly makes a distinct array which would use a lot of memory. Would the solution with the enumeration do the same? Or is the enumeration linked to the Hashtable so that it doesn't need a very large seperated structure in memory ?
    cheers,

  • Query of queries disallows SQL right() function

    We're attempting to do a query of queries using the SQL
    right() function like this:
    select *
    from getresults
    where right([key],charindex('\',reverse([key]),1)-1) not in
    (#quotedvaluelist(getexcluded.file_name)#)
    We've even replaced that where clause with a much more simple
    where right([key])='m'
    just to make sure that it wasn't the nesting functions that
    were causing the problem.
    In either case, we get the error:
    Query of Queries syntax error.
    Encountered "right" at line 0, column 0. Incorrect
    conditional expression,
    Expected one of [like|null|between|in|comparison] condition,
    What SQL functions are disallowed from query of queries?
    Thanks,
    Kris

    Nasty stuff huh. Just happened to discover myself today that
    Left doesn't work. I'd suspect that Aggregate functions are the
    ONLY ones that will work. It would have been nice if they'd at
    least allowed CF vs DB functions in their own "database" language.
    BTW, also discovered that Count() returns Null rather than 0
    when there aren't any per your WHERE clause.

  • Select from Query ? / Dynamic view ? Anything else ?

    Hello,
    This could be a bit challenging. (or maybe not, i hope)
    I have to create a report which is based on 3/4 tables with pretty complex SQL.
    Step 1. I have to use views (in the database currently) to select data from these tables.
    Step 2. Then create the next set of views (in the db) based on the previous views.
    Step 3. Then finally join the last set of views in Reports and create the report based on the PARAMETERS entered.
    This was fine, until the client changed the criteria. Now the views have to be created but the PARAMETERS affect the FIRST set of views.
    That is, the views in the FIRST STEP will have a where condition based on the parameters at RUN TIME.
    I was wondering about how to do this ?
    1. Can I use dynamic views (in db) passing the where condition parameter to the where clause ? Alternatively use DDL in Reports.
    OR
    2. Create a query in Reports and create subsequent QUERIES BASED ON THE FIRST QUERY (like MS Access). Can this be done ?
    3. Any other way ?
    If you need any clarification, I can provide that.
    THANKS for taking the time to read it. It would be great if you could give me any ideas.
    Pat.

    hello,
    you might look into REF-CURSOR-QUERIES for this particular case. it might help.
    regards,
    the oracle reports team

  • Query to get the difference between 2 totals from 2 different queries

    I wanted to know if it is possible to get the difference between 2 totals from 2 different queries. I would explain with an example:
    1st query  - Select sum(homepass) from table 1
    2nd query – select sum(homepass) from table2
    Is it possible to display the difference like-
    Select sum(homepass) from table 1 - sum(homepass) from table2
    I know the above query would gives syntax error but is there a better way or a trick to get the above task accomplished from a single query.
    I hope, my question is clear.
    Please revert with the reply to my query.
    Regards

    tomernitin wrote:
    Try this one also:
    WITH adtn1
    AS
    SELECT 110 val1 FROM dual UNION ALL
    SELECT 100 FROM dual UNION ALL
    SELECT 90  FROM dual UNION ALL
    SELECT 10 FROM dual
    adtn2
    AS
    SELECT 10 val2 FROM dual UNION ALL
    SELECT 20 FROM dual UNION ALL
    SELECT 30  FROM dual UNION ALL
    SELECT 100 FROM dual
    SELECT(Sum(a1.val1)-Sum(a2.val2)) Diff FROM adtn1 a1,adtn2 a2;
    let me know if you still have any doubt.
    Um.... I don't think so. Not with the cartesian join between a1 and 2.

  • Adding values from two different queries in one query

    Hi,
      I have developed a web template by combining 3 queries ,which were created from the same MultiProvider.These queries are having many different selections .Now I need to get the addition of values from these 2 queries into third query.
    Is there any way to combine the selections from these queries into one instead of recreating them again.I tried to use global strucuture but not successful.
    Kindly let me know is there any workaround for this.
    Thanks & Regards,
    Raja

    Hi ,
    You can do it by excel formula.
    sheet 1 --> 1st query
    sheet2 -->2nd query
    sheet3--> put calculations accroding to your requirement based on sheet1 & sheet2 into sheet3.
    Regards
    Pcrao.

  • Query Issue with select level from dual

    Hi,
    I have a question regarding this query. The problem seems that when selecting level from dual while including another table the rows returned seem to increase exponentially.
    I can add distinct and get the correct number of rows but am worried that this will cause a possible performance issue. Am I using the level option wrong?
    I have included details below.
    There are 4 rows in tbl_incidents
    When I run the following queries I get rows returned based on the total number of rows
    select start_date + level - 1, tbl_incidents.incident_id, level
    from dual, tbl_incidents
    where incident_id = 6
    connect by level <= 1;
    returns 1 row
    select start_date + level - 1, tbl_incidents.incident_id, level
    from dual, tbl_incidents
    where incident_id = 6
    connect by level <= 2;
    returns 5 rows
    select start_date + level - 1, tbl_incidents.incident_id, level
    from dual, tbl_incidents
    connect by level <= 3 and incident_id = 6;
    returns 21 rows
    select start_date + level - 1, tbl_incidents.incident_id, level
    from dual, tbl_incidents
    connect by level <= 4 and incident_id = 6;
    returns 85 rows
    select start_date + level - 1, tbl_incidents.incident_id, level
    from dual, tbl_incidents
    connect by level <= 5 and incident_id = 6;
    returns 341 rows
    So with
         r being the number of rows in tbl_incidents and
         l being the number used in the connect by for level and
         q being the number of rows returned by the query
         it appears that
    q(l) = r * q(l-1) + 1
    level 2:     4 * 1 + 1 = 5
    level 3:     4 * 5 + 1 = 21
    level 4:     4 * 21 + 1 = 85
    level 5:     4 * 85 + 1 = 341
    Thanks much,
    Nora

    Hi,
    The dual table is used when you want to do something in SQL when you are not otherwise using a table.
    Generating a "counter table" of the integers 1, 2, 3,..., X is an example
    SELECT  LEVEL   AS n
    FROM    dual
    WHERE   LEVEL   <= x;There is never any point in joining dual to another table, as in
    select  start_date + level - 1
    ,       tbl_incidents.incident_id
    ,       level
    from    dual
    ,       tbl_incidents
    where    incident_id = 6
    connect by  level <= x;You will always get the same more easily by just eliminating dual:
    select  start_date + level - 1
    ,       incident_id
    ,       level
    from    tbl_incidents
    where    incident_id = 6
    connect by  level <= x;It is quite useful and common to join a counter-table to a real table, like this cross-join:
    WITH    counter_table  AS
        SELECT  LEVEL   AS n
        FROM    dual
        WHERE   LEVEL   <= x
    select  start_date + n - 1
    ,       incident_id
    ,       n
    from    tbl_incidents
    ,       counter_table
    where    incident_id = 6

  • How to select data from an aggregate in a customer exit for a query?

    Hi,
    I have written a virtual key figure customer exit for a query. Earlier the selection was from the cube, where there was severe performance issue. So I have created an aggregate, activated and have loaded the data.
    Now when I select that data I find that the Key table is different in development and production. How do I resolve this.
    My code is attached below. The table in developemnt is KEY_100027 and in production is KEY_100004. This code is activated and running in BW development server.
    SELECT
        F~KEY_1000041 AS K____035
         F~KEY_1000271 AS K____035
         F~QUANT_B AS K____051
         F~VALUE_LC AS K____052
    INTO (xdoc_date, xval1, xqty1)
    UP TO 1 ROWS
    FROM
    FROM
    */BIC/E100004 AS F JOIN
    /BIC/E100027 AS F JOIN
    /BIC/DZMM_CGRNU AS DU
    ON FKEY_ZMM_CGRNU = DUDIMID
    JOIN /BI0/SUNIT AS S1
    ON  DUSID_0BASE_UOM = S1SID
    JOIN /BI0/SCURRENCY AS S2
    ON DUSID_0LOC_CURRCY = S2SID
    JOIN /BI0/SMATERIAL AS S3
    *ON FKEY_1000042 = S3SID
    ON FKEY_1000272 = S3SID
    JOIN /BI0/SMOVETYPE AS S4
    *ON FKEY_1000043 = S4SID
    ON FKEY_1000273 = S4SID
    JOIN /BI0/SPLANT AS S5
    *ON FKEY_1000044 = S5SID
    ON FKEY_1000274 = S5SID
    JOIN /BIC/D100004P AS DP
    *ON FKEY_100004P = DPDIMID
    ON FKEY_100027P = DPDIMID
    WHERE
    WHERE
    ( ( ( ( F~KEY_1000041 BETWEEN 20051230 AND 20060630  ) ) AND  ( (
    ( ( ( ( F~KEY_1000271 BETWEEN 20051230 AND 20060630  ) ) AND  ( (
             S3~MATERIAL = <l_0material> ) ) AND  ( (
                s2~movetype BETWEEN '101' AND '102' OR
             s4~movetype BETWEEN '921' AND '922' OR
             s4~movetype BETWEEN '105' AND '106' OR
             s4~movetype BETWEEN '701' AND '701' OR
             s4~movetype BETWEEN '632' AND '632' ) ) AND  ( (
             S5~PLANT = <l_0plant> ) ) AND  ( (
             DP~SID_0RECORDTP = 0  ) ) ) )
    GROUP BY
        ORDER BY F~KEY_1000271 DESCENDING.
          IF sy-subrc NE 0.
            EXIT.
          ENDIF.
        ENDSELECT.
    How do I transport the code and make it work?
    Whats the reason that the two key fields are different.
    I had transported the aggregate from development to production. Activated it and filled the data.
    What is the way out? Please help.
    Regards,
    Annie.

    Hi Sonu,
    The main task is to move the contents of the one internal table to another with some condition.
    First sort and delete the duplicate entries from the First Internal table like below : 
    sort it_tab by material ascending date_modified descending.
    delete adjacent duplicates from it_tab.
    Then move that Internal table contents to another internal table.
    Define another internal table with the same structure as you have first internal table and then
    Second Step :
    it_itab1 = it_itab.
    If you are using seperate Header line and Body then you can do like below :
           it_itab1[] = it_itab[].
    This will fix the issue.
    Please let me know if you need any further explonation.
    Regards,
    Kittu
    Edited by: Kittu on Apr 24, 2009 12:21 PM

  • Selecting random values from an array based on a condition

    Hi All,
    I have a small glitch here. hope you guys can help me out.
    I have an evenly spaced integer array as X[ ] = {1,2,3, ....150}. and I need to create a new array which selects 5 random values from X [ ] , but with a condition that these random values should have a difference of atleast 25 between them.
    for example res [ ] = {2,60,37,110,130}
    res [ ] = {10,40,109,132,75}
    I have been thinking of looping thru the X [ ], and selecting randomly but things look tricky once I sit down to write an algorithm to do it.
    Can anyone think of an approach to do this, any help will be greatly appreciated ...

    For your interest, here is my attempt.
    import java.util.Random;
    public class TestDemo {
        public static void main(String[] args) throws Exception {
            for (int n = 0; n < 10; n++) {
                System.out.println(toString(getValues(5, 25, 150)));
        private final static Random RAND = new Random();
        public static int[] getValues(int num, int spread, int max) {
            if (num * spread >= max) {
                throw new IllegalArgumentException("Cannot produce " + num + " spread " + spread + " less than or equals to " + max);
            int[] nums = new int[num];
            int max2 = max - (num - 1) * spread - 1;
            // generate random offsets totally less than max2
            for (int j = 0; j < num; j++) {
                int next = RAND.nextInt(max2);
                // favour smaller numbers.
                if (max2 > spread/2)
                    next = RAND.nextInt(next+1);
                nums[j] = next;
                max2 -= next;
            // shuffle the offsets.
            for (int j = num; j > 1; j--) {
                swap(nums, j - 1, RAND.nextInt(j));
            // add the spread of 25 each.
            for (int j = 1; j < num; j++) {
                nums[j] += nums[j-1] + spread;
            return nums;
        private static void swap(int[] arr, int i, int j) {
            int tmp = arr;
    arr[i] = arr[j];
    arr[j] = tmp;
    public static String toString(int[] nums) {
    StringBuffer sb = new StringBuffer(nums.length * 4);
    sb.append("[ ");
    for (int j = 0; j < nums.length; j++) {
    if (j > 0) {
    sb.append(", ");
    sb.append(nums[j]);
    sb.append(" ]");
    return sb.toString();

  • How to randomly select data from excel using labview.

    A very good day to all. I am actually working on a system that will be selecting integer number from randomly generated set of number. If that wouldnt be possible, I would like the system to be able to select number from the set of numbers which have already been randomly generated from excel. kindly help me with the solution. To make myself clear, supposing I have set of numbers from 1 to 10, I want a labview setup that will be picking these numbers one after the other either with replacement or without from excel or self generated. I know this is possible in matlab but would prefer labview if possible.  Thanks
    Solved!
    Go to Solution.

    Most, if not all, of the languages I've run across have a rand() function that returns a random number between 0 and 1.  Getting some other range is up to the programmer.  Usual method is to multiply by the range you need and add an offset to adjust the mean.  For instance if you need a random number between 200 and 300 the formula might look like  " rand()*100+200 ".   If you need an integer, you can use the round function (which will leave it as a float with no decimal pportion) or the conversion (to int).    All of this is doable and straightforward in LabVIEW.  Have a look: http://digital.ni.com/public.nsf/allkb/FCCDCD678EEF3A9186256D7B008054F5
    If you feel more comfortable pulling from a file, try this: http://digital.ni.com/public.nsf/allkb/C944B961B59516208625755A005955F2 

Maybe you are looking for