Record selection issue in same table

Hi All
I have the following table
with emp as (
           select '11' A,'aaa' B, '40' C from dual union all
           select '11','bbb', '40' from dual union all
           select '33','ccc', '30' from dual union all
           select '44','ddd', '20' from dual union all
           select '11','eee', '10' from dual
          )My expected results should be
A           B        C
11        aaa      40
11        bbb     40     
11        eee     10Basically requirement is when select different combination of values in column 'B' need to find out what is the 'A' value (this has to be same for all three records)
Hope this make sense.
Cheers
Shabar

Hi all
Sorry for confusing you guys.
Basicall for the following data
{codes}
with emp as (
select '11' A,'aaa' B, '40' C from dual union all
select '11','bbb', '40' from dual union all
select '33','ccc', '30' from dual union all
select '44','ddd', '20' from dual union all
select '11','kkk', '20' from dual union all
select '10','eee', '20' from dual union all
select '11','eee', '10' from dual
I expexted results as11     aaa     40
11     bbb     40
11     eee     10
Ganesh Srivatsav : In your query results are bit different. Sorry I guess its my bad explantion
Cheers
Shabar                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Selecting specific records out of the same table with PICS

    Post Author: nambi
    CA Forum: Formula
    I have a Database table in which we have information for our paint codes,
    This database when accessed through our will display the types of tests we do for the products we manufacture, we manually enter in these results through the software.  When I open up this same table in access I noticed that each test we do is displayed as new entry under the same product, therefore I have several entries for the same product code, and since we have several tests for each I am unable to specifically pull out the data I need.
    For example I need to create a data sheet for our customers displaying the bake time for these all our products the Product code (formkey) is listed multiple times but all I need is to record the Bake (TargetAlphaValue) time. Out of this table I will also need to report on the Gloss. If I use the record selection I am only able to display one type of test although I will need to specify other types as well.  This is the area I have the problem with,
    I have shown in a jpg what I am looking for, would anyone here know how to pull out only the TargetAlphaValue and associate it to the bake and formkey?  Then do the same with the Gloss test and pull up the TargetAlphaValue for that it would be of great help

    Can you be more precise , please :
    - which table stores the people identities ? (I call this one Identity)
    - which table gives the class where the student works in (I cal l this one Claa_attendees)
    - which table gives the instructor of a class (I call this one Class)
    If your issue is that you have one table which stores Itendities , and you need to display Student identity and Instructor Identity, you have to call this table twice in your query , using table aliases . I mean :
    Select Stud_iden.name, Instr_iden.name
    From Identity Stud_iden, Identity Instr_iden, Class_attendees, Class
    Where Class.clas_id = class_attendees.class_id
    and class.instructor_id = Instr_iden.people_id
    and class_attendees.student_id = Stud_iden.people_id
    Is this what you need to do ?

  • How to reatin record selection in a master table

    Hi,
    I have table A with single selection item and detail table B below, both VO based. Once single selection is clicked the detail table shows corresponding result record set. I need to retain the selection of the record in table A once query on table B. is there was to do that?
    Thank you
    Anatoliy

    Hi,
    Refer below links:
    http://oracle.anilpassi.com/master-detail-screen-in-oa-framework-part-i.html
    https://kr.forums.oracle.com/forums/thread.jspa?threadID=2364464
    --Sushant                                                                                                                                                                                                                                                                                                                                                                               

  • Optimization of an update that uses multiple selects on the same table

    Oracle version : 10g
    Hello,
    I have created an UPDATE statement which uses two selects on a single table to do an update according to date criteria.
    Due to the fact that the update has different criteria for updating according to whether the date falls within one of two ranges
    (future or past) two selects were used together with a union between them to unite the results.
    The end result is of course two full table scans and a poorly performing execution.
    The goal is to update a field XDEL (type number) based on a date column value (column XDATE) where the dates of interest
    fall both in the past (less than sysdate minus 45 days) and in the future (greater than sysdate +90 days). For records with XDATE
    values within these ranges, I wish to set field XDEL=1
    For records in the future (>=sysdate+90):
    for a unique combination of XNAME+XCODE, where XDATE is within the date range for update, set XDEL=1
    but for a non-unique combination of XNAME+XCODE+XDATE, update XDEL=1 only for the 'oldest' future record, ie update XDEL for MIN(XDATE) only
    For records in the future (< sysdate+45):
    for a unique combination of XNAME+XCODE, where XDATE is within the date range for update, set XDEL=1
    for a non-unique combination of XNAME+XCODE, update XDEL=1 only for the 'newest' past record, ie update XDEL for MAX(XDATE) only
    The combination of XNAME+XCODE XDATE is unique. As an example of the 'in the past' scenario:
    XNAME | XCODE | XDATE
    ================
    1. AAAA ~ 002 ~ 01/01/2006
    2. AAAA ~ 002 ~ 02/01/2006
    3. AAAA ~ 002 ~ 03/01/2006
    4. XXXX ~ 123 ~ 02/01/2006
    Here, we would update XDEL in record 3. as it corresponds to MAX(XDATE) for the GROUP AAA002 (and we would also update record 4. as a unique record that meets the criteria)
    As an example of the 'in the future' scenario:
    XNAME | XCODE | XDATE
    ================
    1. HHHH ~ 002 ~ 01/01/2011
    2. HHHH ~ 002 ~ 02/01/2011
    3. HHHH ~ 002 ~ 03/01/2011
    4. XXXX ~ 123 ~ 02/01/2011
    Here, we would update XDEL in record 1. as it corresponds to MIN(XDATE) for the GROUP HHHH002 (and of course 4. as a unique record that meets the criteria)
    Here is a query that works, but is slow:
    UPDATE TAB1 SET XDEL=1 WHERE (XNAME,XCODE,XDATE) IN ((SELECT XNAME,XCODE,max(XDATE) FROM TAB1 WHERE XDATE < sysdate-45 GROUP BY XNAME,XCODE) UNION (SELECT XNAME,XCODE,min(XDATE) from TAB1 WHERE XDATE >= sysdate+90 GROUP BY XNAME,XADDR));
    XDATE is a DATE type
    XCODE and XADDR are VARCHAR2
    XDEL is number type
    Any ideas would be greatly appreciated.

    Here is a suggestion. The code is not tested.
    update tab1 t1
       set xdel = 1
    where exists (select null
                     from (
                            select xname,
                                   xcode,
                                   max(case when xdate < sysdate-45 then xdate else null end) xdate1,
                                   min(case when xdate >= sysdate+90 then xdate else null end) xdate2
                              from tab1
                             group by xname, xcode
                          ) t
                    where t1.xname = t.xname
                      and t1.xcode = t.xcode
                      and (t1.xdate = t.xdate1 or t1.xdate = t.xdate2))

  • Record Selection Issue

    I have the following record selection formula:
    not ({TransDetailCustomerView.Route} in [199, 299, 399, 499, 599, 699, 799]) and
    (not HasValue({?SUPPLIER}) OR {TransDetailCustomerView.VendorNo} = {?SUPPLIER}) and
    not {TransDetailCustomerView.VoidFlag} and
    {TransDetailCustomerView.InvoiceDate} = {?DATE RANGE} and
    {TransDetailCustomerView.ChainCode} <> 395 and
    (if {?LOCATION}= "ALL LOCATIONS" then TRUE
    else
    {@LOCATION NAMES}={?LOCATION}) and
    {TransDetailCustomerView.ServiceType} in [1, 5]
    However, when I refresh and preview the report, I get records that are in other service types than 1 or 5.  Does anyone know why this would happen?

    Hi Gayle,
    What I would try, is create a formula, with just part of your select statement in it.
    Then create another formula that has more of the select statement.
    say something like this.
    not ({TransDetailCustomerView.Route} in 199, 299, 399, 499, 599, 699, 799) and
    (not HasValue({?SUPPLIER}) OR {TransDetailCustomerView.VendorNo} = {?SUPPLIER}) then '1'
    or this
    not ({TransDetailCustomerView.Route} in 199, 299, 399, 499, 599, 699, 799) and
    (not HasValue({?SUPPLIER}) OR {TransDetailCustomerView.VendorNo} = {?SUPPLIER}) and
    not {TransDetailCustomerView.VoidFlag}  then "2"
    Then maybe an additional formula like this.
    {TransDetailCustomerView.InvoiceDate} = {?DATE RANGE} and
    {TransDetailCustomerView.ChainCode} 395 and
    (if {?LOCATION}= "ALL LOCATIONS" then "3"
    clear out your selection criteria, so that you return all records.
    Then drop your new formulas in to the details section.
    Hopefully it will be easy to determine where the select is getting the error.

  • Record selection issue in cross tab.

    Hello!
    I have a record  filtering problem. I tried many scenarios, and searched this forum but I cannot find an solution.
    I have a sub-report that contains a cross tab that provides a few summarized fields.
    I have two tables: a table with category of events : (field catID and Catname) and an event table with a CatID, a date field and others number field I use in the cross tab.
    I want my cross tab to show one row per category. The Catname and the summaries.
    Now all is working fine but for one issue. I need to select my event according to a time bracket.
    So I created two time parameters (start and end) and select the event dates between these two dates.
    Now, when selected, any category that does not have an event between these dates are not displayed. I would like them to be shown with "o" values.
    There must be a way of doing this. I just cannot find it.
    Esther

    In order for Crystal to show data, it must be given data to show!
    You will need to base your subreport on an SQL Command.  In that command, put the current SQL used by the report.  To this, do a UNION to a select that selects the category name, and a zero for each field that you are summing in the crosstab.
    As a simplified example, suppose the original SQL was (MS SQL):
    select c.catname, sum(e.quantity) as Quantity
    from categories c, events e
    where c.catid = {?catid parm}
    and c.catid = e.catid
    and e.date between {?start} and {?end}
    This would be changed to
    select c.catname, sum(e.quantity) as Quantity
    from categories c, events e
    where c.catid = {?catid parm}
    and c.catid = e.catid
    and e.date between {?start} and {?end}
    UNION
    select c.catname, 0 as Quantity
    from categories c
    where c.catid = {?catid parm}
    This will return an additional zero record, regardless of what data the original query returns, thus giving Crystal the data needed to display.  Note that the zero value will not affect the results in any way, except causing a zero to be displayed if no data is returned from the original query.
    Just remember that the second SELECT in the UNION has to have the same number of fields, of the same data type, as the first SELECT.
    HTH,
    Carl

  • Update and Select from the same table

    Hello,
    i have this select - i tested it and its working
    [code]
    select
    case
    when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTBT
    else DTF_REEW_201301.KTBT - CTF_REEW_KUM_201301.KTBT
    end
    as KTBT_ISO,
    case
    when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTZN
    else DTF_REEW_201301.KTZN - CTF_REEW_KUM_201301.KTZN
    end
    as KTZN_ISO,
    case
    when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTAB
    else DTF_REEW_201301.KTAB - CTF_REEW_KUM_201301.KTAB
    end as KTAB_ISO,
    DTF_REEW_201301.brnrn,
    DTF_REEW_201301.ktat
       from
    reewcore.CTF_REEW_KUM_201301 CTF_REEW_KUM_201301,
    reewdq.DTF_REEW_201301 DTF_REEW_201301
       where
    (DTF_REEW_201301.BRNRN = CTF_REEW_KUM_201301.BRNRN
    and DTF_REEW_201301.KTAT = CTF_REEW_KUM_201301.KTAT)
    and CTF_REEW_KUM_201301.KTMO = (DTF_REEW_201301.KTMO - 1)
    [/code]
    With the result from KTBT_ISO, KTZN_ISO and KTAB_ISO i want to update the table "reewdq.DTF_REEW_201301" - and this table is in the select-statement!
    I believe, i tried every update-statement - but no update is working.
    I need something like this:
    [code]
    update reewdq.DTF_REEW_201301 t1 set t1.KTBT_ISO=
    select
    case
    when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTBT
    else DTF_REEW_201301.KTBT - CTF_REEW_KUM_201301.KTBT
    end
    as KTBT_ISO
       from
    reewcore.CTF_REEW_KUM_201301 CTF_REEW_KUM_201301,
    reewdq.DTF_REEW_201301 DTF_REEW_201301
       where
    (DTF_REEW_201301.BRNRN = CTF_REEW_KUM_201301.BRNRN
    and DTF_REEW_201301.KTAT = CTF_REEW_KUM_201301.KTAT)
    and CTF_REEW_KUM_201301.KTMO = (DTF_REEW_201301.KTMO - 1)
    t1.KTZN_ISO=
    select
    case
    when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTZN
    else DTF_REEW_201301.KTZN - CTF_REEW_KUM_201301.KTZN
    end
    as KTZN_ISO
       from
    reewcore.CTF_REEW_KUM_201301 CTF_REEW_KUM_201301,
    reewdq.DTF_REEW_201301 DTF_REEW_201301
       where
    (DTF_REEW_201301.BRNRN = CTF_REEW_KUM_201301.BRNRN
    and DTF_REEW_201301.KTAT = CTF_REEW_KUM_201301.KTAT)
    and CTF_REEW_KUM_201301.KTMO = (DTF_REEW_201301.KTMO - 1)
    t1.KTAB_ISO=
    select
    case
    when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTAB
    else DTF_REEW_201301.KTAB - CTF_REEW_KUM_201301.KTAB
    end as KTAB_ISO
       from
    reewcore.CTF_REEW_KUM_201301 CTF_REEW_KUM_201301,
    reewdq.DTF_REEW_201301 DTF_REEW_201301
       where
    (DTF_REEW_201301.BRNRN = CTF_REEW_KUM_201301.BRNRN
    and DTF_REEW_201301.KTAT = CTF_REEW_KUM_201301.KTAT)
    and CTF_REEW_KUM_201301.KTMO = (DTF_REEW_201301.KTMO - 1)
    [/code]
    But this code isn´t working. Has someone an idea please? Can someone please help me.
    Best regards
    Heidi

    Use MERGE:
    merge
      into reewdq.DTF_REEW_201301 t1
      using (
             select  case
                       when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTBT 
                       else DTF_REEW_201301.KTBT - CTF_REEW_KUM_201301.KTBT
                     end as KTBT_ISO,
                     case
                       when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTZN 
                       else DTF_REEW_201301.KTZN - CTF_REEW_KUM_201301.KTZN
                     end as KTZN_ISO,
                     case
                       when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTAB 
                       else DTF_REEW_201301.KTAB - CTF_REEW_KUM_201301.KTAB
                     end as KTAB_ISO,
                     reewdq.ROWID as rid
               from  reewcore.CTF_REEW_KUM_201301 CTF_REEW_KUM_201301, 
                     reewdq.DTF_REEW_201301 DTF_REEW_201301
               where DTF_REEW_201301.BRNRN = CTF_REEW_KUM_201301.BRNRN
                 and DTF_REEW_201301.KTAT = CTF_REEW_KUM_201301.KTAT
                 and CTF_REEW_KUM_201301.KTMO = DTF_REEW_201301.KTMO - 1
            ) t2
      on (
          t1.rowid = t2.rid
      when mathed
        then
          update
             set t1.KTBT_ISO = t2.KTBT_ISO,
                 t1.KTZN_ISO = t2.KTZN_ISO,
                 t1.KTAB_ISO = t2.KTAB_ISO
    SY.

  • Query with many sub-selects on the same table

    Hi,
    Please consider the example below (Oracle 11g):
    create TABLE test1 (order_id number, CODE VARCHAR2(10), VALUE NUMBER);
    insert into test1 VALUES (1, 'A', 100);
    insert into test1 VALUES (1, 'B', 200);
    insert into test1 VALUES (1, 'C', 300);
    insert into test1 VALUES (1, 'D', 400);
    insert into test1 VALUES (2, 'A', 10);
    insert into test1 VALUES (2, 'B', 20);
    SELECT order_id,
           CODE,
           VALUE,
           (SELECT VALUE FROM test1 t1
           WHERE t1.order_id = t.order_id
           AND   t1.code = 'B') b_Value,
           (SELECT SUM(VALUE)/COUNT(*) FROM test1 t1
           WHERE t1.order_id = t.order_id
           AND   t1.code IN ('C', 'D')) cd_Value,
           (SELECT COUNT(*) FROM test1 t1
           WHERE t1.order_id = t.order_id
           AND   t1.code IN ('C', 'D')) cd_qty
    FROM   TEST1 t
    WHERE  CODE = 'A';In my real-life case, I don't have 3 but tens of sub-query columns like those. The performance is OK but I was wondering whether there were a better way in terms of performance and maintainability to write this query.
    I thought of the WITH clause but couldn't see how it could help much.
    Please note that some sub-queries can be more complex than just looking up a column, like in column cd_value/cd_qty.
    Any suggestions?
    Thanks
    Luis

    Simpler, but will go for two table scans. You will have to use outer joins according to your requirement.
    select t1.order_id,
           t1.CODE,
           t1.VALUE,
           max(decode(t2.code,'B',t2.value)) b_value,
           sum(decode(t2.code,'C',t2.value,'D',t2.value,0))/nullif(sum(decode(t2.code,'C',1,'D',1,0)),0)  cd_value,
           sum(decode(t2.code,'C',1,'D',1,0))  cd_qty 
    from TEST1 t1,test1 t2
    where t1.CODE = 'A'
    and t1.ORDER_ID = t2.order_id
    group by t1.order_id,
           t1.CODE,
           t1.VALUEEdited by: jeneesh on Feb 7, 2012 11:54 AM

  • Multiple display formats for several records coming from the same table

    Hello all,
    I want to create one Crystal Reports XI report to display several records coming from one table, but I need different display format for different records from that one table.
    There is a field RecordType and based on that value, the record will be displayed differently on the report page.
    Can I have several sections in the report and to define different SQL query in each of them?
    Example of the report I need to see on paper:
    ================================================
    Summary of 216 vehicles:  (the value 216 comes from record with RecordType=1)
    Vehicle Category    Number of Vehicles
              A                   5          (this value 5 comes from record with RecordType=2)
              B                   7          (this value 7 comes from record with RecordType=3)
              D                   4          (this value 4 comes from record with RecordType=4)
    Category A vehicle numbers:
    2345   6789   8765   5543   3452    (these five values come from records with RecordType=5)
    Category B vehicle numbers:
    9876   8876   9987   4321   6754   5215   4543    (these values come from records with RecordType=6)
    Category D vehicle numbers:
    2343   2344    2348   2377    (these values come from records with RecordType=8)
    ==============================================================
    Text is fixed (labels), number values are coming from table records.
    What would be a good way to do this in Crystal Reports XI ? In Cognos ReportNet, I would just create several Queries (SQL sentences) and place their outputs on a page, one after the other.
    I use Crystal Reports XI R2 and Oracle 10g database through and ODBC connection.
    Thank you,
    Milan

    Obaid and Debi,
    Thank you for your replies.
    I can create multiple sections in the report, but I don't know how to split the 20 records that I get back from the database to be displayed in 5 different report sections.
    How can I define different SQL statement for each of 5 report sections?
    How can I use cross-tabs to display what I need? Can I define SQL statement for each cross-tab and then I could place only RecordType=1 records into cross-tab-1 and all RecordType=2 records into cross-tab-2 ?
    In Cognos ReportNet, I defined 2 Queries (SQL statements) and I just placed them in the report one below the other. Query_1 returns 1 record where RecordType value =1. Query_2 returns 5 records where RecordType value =2 and etc. So each record "section" displays record in the way I want it.
    ================================
    Summary of 216 vehicles:  (the value 216 comes from record where RecordType=1)
    Category A vehicle numbers:
    2345   6789   8765   5543   3452    (these values come from records where RecordType=2)
    ================================
    How can I do that in Crystal Reports XI ?
    How can I run several SQL statements from one report?
    Thank you,
    Milan

  • UPDATE involving the same table in sub query

    DB version: 11.2
    We have a table called SHP_GC_TRACK which has around 8 million records with partitions . In the below UPDATE, it is updating a column based on the SELECT on the same table in a subquery.
    UPDATE shp_gc_track a
       SET f_tran_proc  = 'Y'
    WHERE last_update_date <
              (SELECT MAX (last_update_date)
                 FROM shp_gc_track b
                WHERE a.shp_trx_rowid = b.shp_trx_rowid
                  AND a.c_shp_inst = b.c_shp_inst
                  AND a.f_tran_proc  = b.f_tran_proc
                  AND b.f_ltr_received = 'D'
                  AND f_rec_code IN ('G', 'W')
                  AND b.f_rec_status = 'B'
                  AND b.c_shp_inst = :b1
       AND a.c_shp_inst = :b1
       AND a.f_ltr_received = 'D'             -----------------> part of composite index
       AND a.f_tran_proc  = 'N'              -----------------> part of composite index
       AND a.f_rec_code IN ('G', 'W')      --------------> part of composite index 
       AND a.f_rec_status = 'B';              -----------------> part of composite index  This UPDATE takes a long time to execute and sometime get hung.
    We have a composite index on four columns f_ltr_received, f_rec_code, f_rec_status, f_tran_proc . Explain plan shows this composite index is being used.
    Is there anyway to rewrite this query or any other suggestions ?

    Steve_74 wrote:
    DB version: 11.2
    We have a table called SHP_GC_TRACK which has around 8 million records with partitions . In the below UPDATE, it is updating a column based on the SELECT on the same table in a subquery.
    UPDATE shp_gc_track a
    SET f_tran_proc  = 'Y'
    WHERE last_update_date <
    (SELECT MAX (last_update_date)
    FROM shp_gc_track b
    WHERE a.shp_trx_rowid = b.shp_trx_rowid
    AND a.c_shp_inst = b.c_shp_inst
    AND a.f_tran_proc  = b.f_tran_proc
    AND b.f_ltr_received = 'D'
    AND f_rec_code IN ('G', 'W')
    AND b.f_rec_status = 'B'
    AND b.c_shp_inst = :b1
    AND a.c_shp_inst = :b1
    AND a.f_ltr_received = 'D'             -----------------> part of composite index
    AND a.f_tran_proc  = 'N'              -----------------> part of composite index
    AND a.f_rec_code IN ('G', 'W')      --------------> part of composite index 
    AND a.f_rec_status = 'B';              -----------------> part of composite index  This UPDATE takes a long time to execute and sometime get hung.
    We have a composite index on four columns f_ltr_received, f_rec_code, f_rec_status, f_tran_proc . Explain plan shows this composite index is being used.
    Is there anyway to rewrite this query or any other suggestions ?Tuning updates with subqueries can be hard :(. Sadly my suggestions below are of the try-it-and-see-what-happens variety - nothing certain
    First, check the index. Is it bitmap or b-tree? If b-tree see if the most restrictive columns are listed first - this can help with b-tree index efficiency. Also if b-tree a composite bitmap for columns with lots of repeating values instead might help
    Its a correlated subquery so you can't just run the subquery first putting the result into a scalar varaiable and using the variable in the SQL instead. You can try putting the results of the subuqery w/join keys in a GTT first using the GTT in the SQL to see if I/O is reduced overall during both operations.
    Do you have the licence for the parallel query option? Using parallel DML (this must be turned on manually) might help. Check the docs for the ALTER SESSION command to do this. Also, the PARALLEL_INDEX() hint might help
    Post the execution plan of the SQL

  • Issue using a parameter twice in record selection

    Setup:
    1) Crystal Report: (Client, Start Date, End Date) parameters linked to the Sub reports
    2) Four sub-reports: (All open issues), (Oldest issue), (Average age of open issues), (Average age of closed issues)
    I need to report on issues based on Customer types of "Company" and "Customer."  All of the records I'm reporting on are in the same table (Subset), but the "Client" parameter I'm using exists in two different columns depending on the Customer type.
    ie. My paramter for "Client" is "ABC"
    "ABC" is found in Subset.Sitename for (Company records)
    "ABC" is found in Subset.Companyname for (Customer Records)
    My record selection formula is:
    {Subset.Companyname}={?Pm-?Client} or {Subset.Sitename}={?Pm-?Client}
    Showing the SQL query shows both values filled in correctly, and if I paste the query in SQL, I get the correct result set.  But if I use any kind of "Running total", "Average", "Maximum", etc... functions, Crystal doesn't include my Company records in its evaluations.  It only evaluates Customer records.
    Does anyone have a work-around for this?  Is this is a limitation?

    All Open Issues -- My work-around was:
    1) Running total (count) of open Customer issues
    2) Running total (count) of open Company issues
    3) Formula (sum) function of 1 and 2
    Oldest Issue -- No workaround yet; Parameters listed above are in the Record selection
    1) Datediff between Received date and Current date
    2) Maximum of the Datediff results
    Average Open - No workaround yet; Parameters listed above are in the Record selection
    1) Datediff between Received and Current Date
    2) Average of Datediff results
    Average Closed - No workaround yet; Parameters listed above are in the Record selection
    1) Datediff between Received Date and Closed Date
    2) Average of Datediff results

  • How to compare two fields from the same table in the select statement

    Hi, friends
    I try to compare tow fields from the same table, but no result,
    For example, this
    data: cptotchek tyep i.
    select count(*) into cptotchek
    from aufk where erdat = aufk-idat2 .
    The result is  cptotchek = 0, but there are the records in aufk , where,  aufk-erdat = aufk-idat2.
    Please, help me, i don't use the loop statement for optimize my program.
    Regards

    Hi  ,
           it will not return  any value   when you are using   column of same table 
           such as Date Field   , Because  while Using Aggregate Function  it will not check with self column
    .      For that you have to take data in one internal table and then you can work on it  .
         And if you are worried about Performance  it will not affect  , untill you are selecting only required data  .
    you can try this way  .
    data: cptotchek type i.
    types : begin of  w_aufk.
            include structure aufk  .
          types : end of  w_aufk .
    data : it_aufk type standard table of w_aufk with header line  .
    select * into corresponding fields of table it_aufk
    from aufk  .
    loop at it_aufk .
    if it_aufk-erdat  = it_aufk-idat2 .
    write : / it_aufk-erdat , it_aufk-idat2 .
    else .
    delete it_aufk .
    endif  .
    endloop.
    Regards
    Deepak.

  • Inserting Record In same table through triggers.

    Hi,
    I've a table cus_mst ( cus_div_cd vachar2(1), cus_cd varchar2(5), cus_nm varchar2(100) )
    Records are inserted in this table through forms ...
    We need to automatically insert a record with a diff div_cd for any record inserted in the table .
    If div_cd 'I' is entered automatically a record with div cd 'S' with other coulmns having same values should get inserted .
    In case div_cd is 'S' then record with div_cd 'I' should get created.
    Eg : If in insert ( 'S', 'A0001', 'ABC COmpany' ); another record with values ( 'I', 'A0001', 'ABC Comapny' ) gets created;
    One way to do is to insert records in a view ( on the table ) and use instead of trigger to insert the corresponding record. But that is not possible as development team has to change form and use view instead of table.
    Have tried doing it by populating a collection in-each-row trigger and then using statment level trigger to insert from the collection. But this leads to recursive error.
    Would be great to get more insights into this..
    thanks
    cheers
    Jaani

    Hi,
    Within the following script you need to make adjustments according to your needs about the columns you need to test. But this might help you.
    Sorry for the layout. But I was not able to adjust it in a short time.
    drop table ad_test
    create table ad_test ( col1 varchar2(1), col2 varchar2(5), col3 varchar2(100) )
    create or replace package ad_test_pkg is
    procedure initialize_postpone ;
    procedure postpone_record( r_atst in ad_test%rowtype ) ;
    procedure handle_postponed_records ;
    end ad_test_pkg ;
    create or replace package body ad_test_pkg is
    type type_atst is table of ad_test%rowtype index by binary_integer ;
    t_atst type_atst ;
    procedure initialize_postpone is
    begin
    t_atst.delete ;
    end initialize_postpone ;
    procedure postpone_record( r_atst in ad_test%rowtype ) is
    begin
    t_atst(t_atst.count) := r_atst ;
    end postpone_record ;
    procedure handle_postponed_records is
    cursor c_test( cpiv_col1 in ad_test.col1%type ) is
    select 'x'
    from ad_test
    where col1 = cpiv_col1
    r_test c_test%rowtype ;
    r_atst ad_test%rowtype ;
    begin
    for i in t_atst.first .. t_atst.last
    loop
    r_atst := t_atst(i) ;
    if r_atst.col1 = 'I'
    then
    r_atst.col1 := 'S' ;
    else
    r_atst.col1 := 'I' ;
    end if ;
    open c_test( cpiv_col1 => r_atst.col1 ) ;
    fetch c_test into r_test ;
    if c_test%found
    then
    close c_test ;
    else
    close c_test ;
    insert into ad_test
    ( col1
    , col2
    , col3
    ) values
    ( 'S'
    , r_atst.col2
    , r_atst.col3
    end if ;
    end loop ;
    end handle_postponed_records ;
    end ad_test_pkg ;
    create or replace trigger test_ad_bis
    before insert on ad_test
    begin
    ad_test_pkg.initialize_postpone ;
    end ;
    create or replace trigger test_ad_air
    after insert on ad_test for each row
    declare
    r_atst ad_test%rowtype ;
    begin
    r_atst.col1 := :new.col1 ;
    r_atst.col2 := :new.col2 ;
    r_atst.col3 := :new.col3 ;
    ad_test_pkg.postpone_record( r_atst => r_atst ) ;
    end ;
    create or replace trigger test_ad_ais
    after insert on ad_test
    begin
    ad_test_pkg.handle_postponed_records ;
    end ;
    insert into ad_test values ( 'I', 'A0001', 'ABC COmpany') ;
    select * from ad_test ;
    Greets,
    Ad
    Edited by: loaddev on 10-nov-2010 4:47

  • Parent/child records from same table

    I want to create a query that is a union such that the 2nd resultset is based on the 1st resultset. I have a table that has parent/child records in the same table.
    Table: EVENTS
    EVENT_ID
    PARENT_EVENT_ID
    CREATED_DATE
    (other columns)
    if PARENT_EVENT_ID is null then it is a parent record, else it is a child record. I want to select all parent records then union them with all the associated child records...something like this:
    select * from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null -- All parents
    union
    select * from EVENTS where PARENT_EVENT_ID in (select EVENT_ID from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null) -- include any children of parents selected from above
    This works but it's kind of ugly, I want to avoid using the sub-select in the 2nd because it is a repeat of the 1st statement, is there a way to alias the first statement and just refer to it in the 2nd query?

    Hi,
    kev374 wrote:
    Thanks, one question...
    I did a test and it seems the child rows have to also satisfy the parent row's where clause, take this example:
    EVENT_ID|PARENT_EVENT_ID|CREATED_DATE
    2438 | (null) | April 9 2013
    2439 | 2438 | April 11 2013
    2440 | 2438 | April 11 2013
    select * from EVENTS where CREATED_DATE < sysdate - 9
    start with EVENT_ID = 2438
    connect by PARENT_EVENT_ID = prior EVENT_IDSo you've changed the condition about only wanting roots and their children, and now you want descendants at all levels.
    This pulls in record #2438 (per the sysdate - 9 condition) but 2439 and 2440 are not connected. Is there a way to supress the where clause evaluation for the child records? I just want to pull ALL child records associated with the parent and only want to do the date check on the parent.Since the roots (the only rows you want to exclude) have LEVEL=1, you can get the results you requested like this:
    WHERE   created_date  < SYSDATE - 9
    OR      LEVEL         > 1However, since you're not ruling out the grandchildren and great-grandchildren any more, why wouldn't you just say:
    SELECT  *
    FROM    events
    WHERE   created_date     < SYSDATE - 9
    OR      parent_event_id  IS NOT NULL;?
    CONNECT BY is slow. Don't use it if you don't need it.
    If you x-reference my original query:
    select * from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null -- All parents
    union
    select * from EVENTS where PARENT_EVENT_ID in (select EVENT_ID from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null) -- include any children of parents selected from above
    The 2nd select does not apply the created_date < sysdate - 90 on the children but rather pulls in all related children :)Sorry; my mistake. That's what happens when you don't post sample data, and desired results; people can't test their solutions and find mistakes like that.

  • [Urgent] Issue with Selected rows in Advanced table

    [I have searched archive and found lots of mails on same issue but none were conclusive so i am asking this again]
    Hi All,
    I have created an advanced table and i want to have functionality of deleting selected rows.
    For implementation of this functionality, i have created a selectflag transient attribute [varchar2] and linked it to multiple select item of Advanced table but the table always returns null for selectflag attribute irrespective of row being selected or not.
    One thing i have noticed is that i can't supply 'checked value' and 'unchecked value' property in advanced table multiple select item. Is that the issue?
    Can anybody please guide, its quite urgent.
    Regards
    Lokesh

    Hi Reetesh,
    Thanks for the reply.
    Yes, you are right i am using same AM at 2 different places.
    Let me just elaborate a little about my implementation:
    I have a Page layout region and within this page layout, i have a query bean which performs results based search.
    Within this query bean, i have added an Advanced table within that query bean to display the results.
    Now coming to multiple AM issue:
    1. Page Layout region must have one AM or its an error.
    2. If i donot add an AM to advanced table, it doesn't return rows.
    So do i need to have 2 diferent AM's for this implementation?
    Regards
    Lokesh

Maybe you are looking for