SSAS Max date in grouped set of records

I have a query where I need to pull back the latest risk assessment rating for a record, but need to do this for all records from the query. I have MS
SSRS Report Builder (V3) as the only way to access this data and no access to modify the underlying cubes which are provided by a supplier.
My basic MDX which pulls out the data needed is the following:
SELECT
NON EMPTY {
[Measures].[No of Investigations]
} ON COLUMNS,
NON EMPTY { (
[Investigation Indicators and Text Fields].[Investigation Reference Number].[Investigation Reference Number].ALLMEMBERS *
[Risk Assessment Rating].[Risk Rating].[Risk Rating].ALLMEMBERS *
[Risk Assessment Completed Date].[Date].[Date].ALLMEMBERS *
[Risk Assessment Completed Time].[Time HHMM].[Time HHMM].ALLMEMBERS
) } ON ROWS
FROM [Investigation]
which leaves my Date and Time needing to be concatenated. I have carried this out as a calculated field but am unable to then test for a max value as it gives me an error around using an aggregate function.
Is anyone able to provide me with any ideas on how to carry this out, either via the MDX statement
or subsequently. Ideally I would like to be able to create the results in two ways - one with all records and a marker showing which is the latest assessment, and one which just pulls back the subset via MDX.
For clarity the source system holds Investigation records as the core item of interest, and these can have multiple risk assessments attached to them (of different types). I need to return the latest risk assessment against each investigation. If at all possible
it would be good to return all investigations, with or without risk assessments, as the missing records need to be quality assured. 
Thanks for any help, ideas or pointers on this. 

Hi Steven,
According to your description, you want to marker the Max date in the assemessments, right?
Generally, when creating a date dimension in a SSAS project, the dimension members were sorted in date order. So the last date is the max date. We can get the last date using ClosingPeriod function. Here is a sample function for you reference.
with member [measures].[a]
as
ClosingPeriod ([Date].[Calendar].[Date],[Date].[Calendar].currentmember).name
select {[measures].[a]} on 0,
[Date].[Calendar].[Month].members on 1
from
[Adventure Works]
Reference
http://msdn.microsoft.com/en-us/library/ms145584.aspx
Regards,
Charlie Liao
TechNet Community Support

Similar Messages

  • How to devide the set of records into groups in SQL itself.

    Hi , i am using 10.2.4.0 of oracle.
    I am having one requirement, in which i have to devide the set of records into certain groups , so that they can be executed partly but not in one run.
    So in the 'SELECT' clause itself i want to asssign particular value (may be 1 )to first 50000 records then another value(may be 2) to next 10000, like wise. And again the total count of records will also varry time to time , if the total count of record set is less than 10000 , then it should only assign '1' to all the records. i will set the group values (1,2,3...) as another column itself.
    Can you please let me know if this can be done in SQL without going for PLSQL?

    Hi,
    That's called a Pagination Query , and here's one way to do it:
    WITH     got_grp          AS
         SELECT     x.*
         ,     CEIL ( ROW_NUMBER () OVER (ORDER BY  x_id) 
                   / 50000
                   )          AS grp
         FROM     table_x  x
    --     WHERE     ...          -- If you need any filtering, put it here
    SELECT     *               -- Or list the columns you want
    FROM     got_grp
    WHERE     grp     = 1
    ;ROW_NUMBER () OVER (ORDER BY x_id)     assigns unique integers 1, 2, 3, ... to all all rows, in the same order as x_id (even if x_id is not unique).
    CEIL (ROW_NUMBER () OVER (ORDER BY x_id) / 50000)     maps the 1st 50,000 of those numbers to 1, the 2nd 50,000 to 2, and so on.
    Analytic functions (like ROW_NUMBER) as computed after the WHERE clause is applied, so, to use the results in a WHERE clause, then you need to compute them in a sub-query. If you just want to display the number, and not use it in a WHERE clause, then you don't need a sub-query.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • Select max date from a table with multiple records

    I need help writing an SQL to select max date from a table with multiple records.
    Here's the scenario. There are multiple SA_IDs repeated with various EFFDT (dates). I want to retrieve the most recent effective date so that the SA_ID is unique. Looks simple, but I can't figure this out. Please help.
    SA_ID CHAR_TYPE_CD EFFDT CHAR_VAL
    0000651005 BASE 15-AUG-07 YES
    0000651005 BASE 13-NOV-09 NO
    0010973671 BASE 20-MAR-08 YES
    0010973671 BASE 18-JUN-10 NO

    Hi,
    Welcome to the forum!
    Whenever you have a question, post a little sample data in a form that people can use to re-create the problem and test their ideas.
    For example:
    CREATE TABLE     table_x
    (     sa_id          NUMBER (10)
    ,     char_type     VARCHAR2 (10)
    ,     effdt          DATE
    ,     char_val     VARCHAR2 (10)
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('15-AUG-2007', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('13-NOV-2009', 'DD-MON-YYYY'), 'NO');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('20-MAR-2008', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('18-JUN-2010', 'DD-MON-YYYY'), 'NO');
    COMMIT;Also, post the results that you want from that data. I'm not certain, but I think you want these results:
    `    SA_ID LAST_EFFD
        651005 13-NOV-09
      10973671 18-JUN-10That is, the latest effdt for each distinct sa_id.
    Here's how to get those results:
    SELECT    sa_id
    ,         MAX (effdt)    AS last_effdt
    FROM      table_x
    GROUP BY  sa_id
    ;

  • Query - Filter by a specific dynamic date - Return only the max date record

    Hello experts,
    I'm building a query. In this query I have a filter named validity date. I need to select a record where the max date is less than this filter.
    For example:
    Comp. Code | Plant | Mat. | Cost Type | Valid. Date | Value
    0000000001   00001  0001  xxxxxxxx    12.05.2008   2,00
    0000000001   00001  0001  xxxxxxxx    09.05.2008   1,00
    0000000001   00001  0001  xxxxxxxx    05.05.2008   0,50
    If the user set 13.05.2008 in the filter, the report should return:
    0000000001   00001  0001  xxxxxxxx    12.05.2008   2,00
    If the user set 11.05.2008 in the filter, the report should return:
    0000000001   00001  0001  xxxxxxxx    09.05.2008   1,00
    If the user set 08.05.2008 in the filter, the report should return:
    0000000001   00001  0001  xxxxxxxx    05.05.2008   0,50
    The problem is that the date will be dynamic and I'll need to return just one line for a combination of Company Code, Plant, Material and Cost Type. First of all I would like to know the best way to do it. Do I need to use virtual key figure? If so, anyone could tell me some steps to do it?
    Thanks in advance,
    Helder

    Not Virtual KeyFigure.
    You can achieve this with Restricted KeyFigure with the restriction with CalDay (Variable) which user input while Running the Query. Its more like a Bucket. SAP Delivered Buckets Query is in the below link. Check that query you will understand better about Bucket.
    http://help.sap.com/saphelp_nw04/helpdata/en/40/94af39a3488979e10000000a11402f/content.htm
    If not clear try to Install the BC Query and play with that you will know better.
    Thanks
    Sriram

  • Getting the last set of records based on a Date Field

    Hi All
    i have the followings data set in a table
    TRACK_ID_GRP     TRACK_ID_NBR     TRACK_SAMPLE_ID     START_DATE
    970150                      129700104071     64260                        8/6/2002
    970150                      229700101893     64261                        8/6/2002
    970150                     149700101893     64262                        8/6/2002
    970150                       97015011     79252                        9/19/2005
    970150                       97015023     79255                        9/19/2005
    970150                       97015013     79253                         9/19/2005
    970150                       97015021     79254                        9/19/2005
    970040                      129900105213     56155                         9/26/2000
    970040                                 1101     29841                        6/9/1998
    970040                       97004023     143349                        10/28/2008
    970040                              2101     29842                        6/9/1998
    970040                        97004021     143348                        10/28/2008
    970040                       97004011     143346                        10/28/2008
    970040                      149700101903     64196                       7/16/2002
    970040                              2301     29844                      6/9/1998
    970040                         97004013     143347                         10/28/2008
    970040                                  1301       29843                        6/9/1998I need to get only those records with the latest date and i'm using the following query
    SELECT t.track_id_grp, t.track_id_nbr, t.track_sample_id,
           MAX (t.start_date) OVER (PARTITION BY t.track_id_grp) AS start_date
      FROM track_table t
    WHERE t.track_id_grp IN ('970150', '970040')And i'm getting the following dataset
    TRACK_ID_GRP     TRACK_ID_NBR     TRACK_SAMPLE_ID     START_DATE
    970040                      1.299E+11     56155     10/28/2008
    970040                      1101                     29841     10/28/2008
    970040                      97004023                     143349     10/28/2008
    970040                      2101                     29842     10/28/2008
    970040                      97004021                     143348     10/28/2008
    970040                      97004011                     143346     10/28/2008
    970040                      1.497E+11     64196     10/28/2008
    970040                      2301                     29844     10/28/2008
    970040                      97004013                     143347     10/28/2008
    970040                      1301                     29843     10/28/2008
    970150                      1.297E+11     64260     9/19/2005
    970150                      97015011                     79252     9/19/2005
    970150                      97015021                     79254     9/19/2005
    970150                      2.297E+11     64261     9/19/2005
    970150                      97015013                     79253     9/19/2005
    970150                      97015023                     79255     9/19/2005
    970150                      149700101903     64262     9/19/2005And i was expecting the following dataset
    TRACK_ID_GRP     TRACK_ID_NBR     TRACK_SAMPLE_ID     START_DATE
    970150                      97015011                             79252     9/19/2005
    970150                      97015023                             79255     9/19/2005
    970150                      97015013                             79253     9/19/2005
    970150                      97015021                             79254     9/19/2005
    970040                      97004023                             143349     10/28/2008
    970040                      97004021                             143348     10/28/2008
    970040                      97004011                             143346     10/28/2008
    970040                      97004013                             143347     10/28/2008I was expecting to get only those records with the latest date, instead i'm getting all the records with the max date in it, please need help or advice.
    Thanks

    Try this -
    SELECT track_id_grp, track_id_nbr, track_sample_id, start_date
      FROM (SELECT t.track_id_grp, t.track_id_nbr, t.track_sample_id,
                   t.start_date,
                   ROW_NUMBER () OVER (PARTITION BY t.track_id_grp, t.track_sample_id ORDER BY t.start_date DESC)
                                                                            AS rn
              FROM track_table t
             WHERE t.track_id_grp IN ('970150', '970040'))
    WHERE rn = 1let me know if that works.
    Edited by: Sri on Apr 28, 2011 9:24 AM

  • Trying to get max date grouped by type

    hello,
    i have a request table with:
    request name
    request start date
    The requests run daily so i have multiple records. In answers i want to display request name and the max(request start date), grouped by request name. Is it possible to due this in answers only? if i must use the repository how do i do it? I'm new to building subject areas.

    You can do this in answers only, If you dont have access to RPD.
    Sol1: Create a report with two columns request name,request start date. Open pivot table and add request start date to measures and apply Aggregation of Max on date.
    sol2: Create a report with two columns request name,request start date, Change the Fx of request start date to max(request start date by request name) . This way table view also show request max date by request names.

  • Same set of Records not in the same Data package of the extractor

    Hi All,
    I have got one senario. While extracting the records from the ECC based on some condition I want to add some more records in to ECC. To be more clear based on some condition I want to add addiional lines of data by gving APPEND C_T_DATA.
    For eg.
    I have  a set of records with same company code, same contract same delivery leg and different pricing leg.
    If delivery leg and pricing leg is 1 then I want to add one line of record.
    There will be several records with the same company code contract delivery leg and pricing leg. In the extraction logic I will extract with the following command i_t_data [] = c_t_data [], then sort with company code, contract delivery and pricing leg. then Delete duplicate with adjustcent..command...to get one record, based on this record with some condition I will populate a new line of record what my business neeeds.
    My concern is
    if the same set of records over shoot the datapackage size how to handle this. Is there any option.
    My data package size is 50,000. Suppose I get a same set of records ie same company code, contract delivery leg and pricing leg as 49999 th record. Suppose there are 10 records with the same characteristics the extraction will hapen in 2 data packages then delete dplicate and the above logic will get wrong. How I can handle this secnaio. Whether Delta enabled function module help me to tackle this. I want to do it only in Extraction. as Data source enhancement.
    Anil.
    Edited by: Anil on Aug 29, 2010 5:56 AM

    Hi,
    You will have to do the enhancement of the data source.
    Please follow the below link.
    You can write your logic to add the additional records in the case statement for your data source.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c035c402-3d1a-2d10-4380-af8f26b5026f?quicklink=index&overridelayout=true
    Hope this will solve your issue.

  • Count(*) with group by max(date)

    SQL> select xdesc,xcust,xdate from coba1 order by xdesc,xcust,xdate;
    XDESC XCUST XDATE
    RUB-A 11026 01-JAN-06
    RUB-A 11026 05-JAN-06
    RUB-A 11026 08-JAN-06
    RUB-A 11027 10-JAN-06
    RUB-B 11026 02-JAN-06
    RUB-B 11026 08-JAN-06
    RUB-B 11026 09-JAN-06
    RUB-C 11027 08-JAN-06
    I want to make sql that result :
    XDESC     COUNT(*)
    RUB-A     2
    RUB-B 1
    RUB-C 1
    Criteria : GROUPING: XDESC XCUST AND MAX(DATE)
    bellow mark *** that was selected in count.
    XDESC XCUST XDATE
    RUB-A 11026 01-JAN-06
    RUB-A 11026 05-JAN-06
    RUB-A 11026 08-JAN-06 ***
    RUB-A 11027 10-JAN-06 ***
    ---------------------------------------------------------COUNT RUB-A = 2
    RUB-B 11026 02-JAN-06
    RUB-B 11026 08-JAN-06
    RUB-B 11026 09-JAN-06 ***
    ---------------------------------------------------------COUNT RUB-B = 1
    RUB-C 11027 08-JAN-06 ***
    --------------------------------------------------------COUNT RUB-C = 1
    Can Anybody help ?
    I tried :
    select xdesc,max(xdate),count(max(xdate)) from coba1 group by xdesc
    ERROR at line 1:
    ORA-00937: not a single-group group function
    Thank

    This one is duplicate. see the following link
    Count(*) with group by max(date)
    Thanks

  • In mdx how to get max date for all employees is it posible shall we use group by in mdx

    in mdx how to get max date for all employees is it posible shall we use group by in mdx
    example
    empno  ename date
    1         hari        12-01-1982
    1         hari        13-06-2000
    by using above data i want to get max data

    Hi Hari3109,
    According to your description, you want to get the max date for the employees, right?
    In your scenario, do you want to get the max date for all the employees or for each employee? In MDX, we have the Max function to achieve your requirement. You can refer to Naveen's link or the link below to see the details.
    http://www.sqldbpros.com/2013/08/get-the-max-date-from-a-cube-using-mdx/
    If this is not what you want, please provide us more information about the structure of you cube, so that we can make further analysis.
    Regards,
    Charlie Liao
    TechNet Community Support

  • GROUP BY GROUPING SETS for a selected month and for year to date

    Below is a code example to demonstrate this question:
    declare @test table (ID int, Quantity int, Day date);
    insert into @test values
    (4, 500, '1/18/2014'),
    (4, 550, '1/28/2014'),
    (7, 600, '1/10/2014'),
    (7, 750, '1/11/2014'),
    (7, 800, '1/20/2014'),
    (1, 100, '1/2/2014'),
    (1, 125, '1/10/2014'),
    (8, 300, '1/7/2014'),
    (9, 200, '1/17/2014'),
    (9, 100, '1/22/2014'),
    (4, 900, '2/18/2014'),
    (4, 550, '2/28/2014'),
    (7, 600, '2/10/2014'),
    (7, 700, '2/11/2014'),
    (7, 800, '2/20/2014'),
    (1, 100, '2/2/2014'),
    (1, 150, '2/10/2014'),
    (8, 300, '2/7/2014'),
    (9, 200, '2/17/2014'),
    (9, 100, '2/22/2014'),
    (4, 500, '3/18/2014'),
    (4, 550, '3/28/2014'),
    (7, 600, '3/10/2014'),
    (7, 750, '3/11/2014'),
    (7, 800, '3/20/2014'),
    (1, 100, '3/2/2014'),
    (1, 325, '3/10/2014'),
    (8, 300, '3/7/2014'),
    (9, 200, '3/17/2014'),
    (9, 100, '3/22/2014'),
    (4, 500, '4/18/2014'),
    (4, 550, '4/28/2014'),
    (7, 100, '4/10/2014'),
    (7, 750, '4/11/2014'),
    (7, 800, '4/20/2014'),
    (1, 100, '4/2/2014'),
    (1, 325, '4/10/2014'),
    (8, 300, '4/7/2014'),
    (9, 200, '4/17/2014'),
    (9, 100, '4/22/2014'),
    (4, 500, '5/18/2014'),
    (4, 550, '5/28/2014'),
    (7, 600, '5/10/2014'),
    (7, 750, '5/11/2014'),
    (7, 50, '5/20/2014'),
    (1, 100, '5/2/2014'),
    (1, 325, '5/10/2014'),
    (8, 300, '5/7/2014'),
    (9, 200, '5/17/2014'),
    (9, 100, '5/22/2014');
    --detail
    select *
    from @test;
    --aggregation
    select
    TotalQuantity = sum(Quantity),
    [Month] = month(Day)
    from @test
    group by
    grouping sets
    (month(Day)),
    (year(Day))
    go
    This is the aggregation query result:
    However, the desired result is to return only two rows: one row for month 3 and the other row for year to date (in the picture above YTD is the row that appears with {null} in the Month column).  Is there a way to achieve this goal by modifying the
    sample code above?  The requirement is to only read the data once (do not want a solution that involves a UNION which implies reading the data twice).

    you can add required filters in having clause. Here is the query -
    select
    TotalQuantity = sum(Quantity),
    [Month] = month(Day)
    from @test
    group by
    grouping sets
    (month(Day)),
    (year(Day))
    having
    month(Day) = 3 or month(Day) is null;

  • Max date

    I'm trying to pull records that have the max date from multiple subqueries. I've tried different sql statements, but am not able to get the results I want. I want the last record only from the three rows in the result set (the latest/max date). I'm thinking I need to do a max(date) in the from clause and then select out of it but I'm having difficulties.
    Any suggestions welcome!
    Example:
    select w.name, m.ida2a2, m.role, m.ida3a4, max(m.updatestampa2) as "UPDATE"
    from map m , user w
    where m.ida2a2 in (select ida3a5
    from link
    where ida3b5 in (select ida3teamid
    from pdoc)
    and role in ('PI')
    and ida3a4 != 0
    and w.ida2a2 = m.ida3a4
    group by w.name,m.ida2a2, m.role, m.ida3a4
    SQL Results:
    NAME Ida2a2 ROLE Ida3a4 UPDATE
    stella 78420 PI 6171 16-DEC-05
    stella 88057 PI 6171 20-DEC-05
    stella 123432 PI 6171 06-JAN-06

    C,
    Thanks for your help. I don't think I explained myself clearly, may the below will help me clarify.
    I want the max update for each group of rows only. ie stella 06-JAN-06, carson 09-JAN-06, lee I need to get the hour,minute, and seconds to figure out which 31-JAN-06 is max, but I wanted the main algorthim correct first.
    For example:
    group one of result set rows
    NAME Ida2a2 ROLE Ida3a4 UPDATE
    stella 78420 PI 6171 16-DEC-05
    stella 88057 PI 6171 20-DEC-05
    stella 123432 PI 6171 06-JAN-06
    carson 79138 PI 6207 16-DEC-05
    carson 90679 PI 6207 20-DEC-05
    carson 130781 PI 6207 09-JAN-06
    lee 227198 PI 215068 30-JAN-06
    lee 390372PI 215068 31-JAN-06
    lee 390682PI 215068-31-JAN-06

  • The ADO NET Source was unable to process the data. ORA-64203: Destination buffer too small to hold CLOB data after character set conversion.

     We developed a SSIS Package to pull the data From Oracle source to Sql Server 2012. Here we used ADO.Net source to pull the records from Source but getting the below error after pulling some 40K records.
      [ADO NET Source [2]] Error: The ADO NET Source was unable to process the data. ORA-64203: Destination buffer too small to hold CLOB data after character set conversion.
    [SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. 
     The PrimeOutput method on ADO NET Source returned error code 0xC02090F5. 
     The component returned a failure code when the pipeline engine called PrimeOutput(). 
    The meaning of the failure code is defined by the component, 
    but the error is fatal and the pipeline stopped executing. 
     There may be error messages posted before this with more 
    information about the failure.
    Anything that we can do to fix this?

    Hi,
      Tried both....
      * Having schema type as Nvarchar(max). - Getting the same error.
      * Instead of ADO.Net Source used OLEDB Source with driver as " Oracle Provide for OLE DB" Getting error as below.
           [OLE DB Source [478]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
           [SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on OLE DB Source returned error code 0xC0202009.  The component returned a failure
    code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the
    failure.
    Additional Info:
       * Here the Source task is getting failed not the conversion or destination task.
    Thanks,
    Loganathan A.

  • Max Date Function

    Hi,
    I have the following columns in a report:
    Vendor Name
    Trade date
    Prod Desc
    Order Type
    Qty
    Gross Amt
    I need to display only those rows where trade date = max(trade date).
    I am aware of the MAX analytic function, but it keeps giving me an error.
    Could someone please let me know how to achieve this scenario.
    Thanks.

    Hi
    As pupppethead mentioned, it doesn't look as though you need a PARTITION BY clause.
    A straight MAX(Trade Date) OVER () = Trade Date should suffice. The OVER() tells Discoverer to look at all dates in the query. You will only need a PARTITION BY if you are using Page Items or Group Sorts and you wanted a different date in each set.
    By the way, as a word of warning, be very careful not to name items in folders or workbooks using Oracle reserved words. Naming an item as Desc is dangerous because that is the name of the descending switch in an ORDER BY clause of an analytic function. Thus, if you have for example something called ITEM DESC and try to do this:
    RANK() OVER(ORDER BY ITEM DESC) you will have serious problems because the database (not Discoverer) will think you want to sort ITEM descending. Either ITEM does not exist and you will get an error or it does exist and you will end up with the sort on the wrong item.
    Imagine also if you named something ORDER BY and then place this in a PARTITION BY clause like this:
    MAX(Trade Date) OVER (PARTITION BY ORDER BY)
    Interesting conundrum, don't you think?
    Best wishes
    Michael

  • Pass a set of Records form Form to a Report

    Hi,
    Lets say that I've already fetched a set of records on Oracle Form, and I want to pass these reocrds to a Report " on the Report I dont wana use range or where clause to give me these recods"
    Any ideas how to do that please?
    Thanks!

    Passing a (Forms) Record Group as DATA_PARAMETER to Reports:
    First example:
    Forms code (in WHEN-BUTTON-PRESSED trigger) calls reports module
    and sends record group "rg_dept" (populated from :SYSTEM.LAST_QUERY) as parameter:
    DECLARE
    rg_id_l RECORDGROUP;
    rg_name_l VARCHAR2 (30) := 'RG_DEPT';
    status_l NUMBER;
    pl_id_l PARAMLIST;
    pl_name_l VARCHAR2 (30) := 'PARAM_LIST';
    BEGIN
    rg_id_l := FIND_GROUP (rg_name_l);
    IF NOT ID_NULL (rg_id_l) THEN
    DELETE_GROUP (rg_id_l);
    END IF;
    rg_id_l := CREATE_GROUP_FROM_QUERY (rg_name_l, :SYSTEM.LAST_QUERY);
    status_l := POPULATE_GROUP (rg_id_l);
    IF status_l <> 0 THEN
    RAISE FORM_TRIGGER_FAILURE;
    END IF;
    pl_id_l := GET_PARAMETER_LIST (pl_name_l);
    IF NOT ID_NULL (pl_id_l) THEN
    DESTROY_PARAMETER_LIST (pl_id_l);
    END IF;
    pl_id_l := CREATE_PARAMETER_LIST (pl_name_l);
    ADD_PARAMETER (pl_id_l, 'Q_1', DATA_PARAMETER, rg_name_l);
    RUN_PRODUCT (REPORTS, 'rec_group', SYNCHRONOUS, RUNTIME, FILESYSTEM, pl_id_l, NULL);
    END;
    Reports module must have query with the same name as parameter in ADD_PARAMETER
    statement (in this code - "Q_1"), and SQL Query Statement in Reports must have
    same number and type of columns as record group, for example:
    SELECT ROWID, 1 deptno, 'x' dname, 'x' loc FROM DUAL
    And - we can't pass a DATA_PARAMETER to a child query in Report Builder.
    Data passing is supported only for master queries.
    Second example:
    Forms transfers to Reports records from "dept" block,
    using non-query record group (populated from Forms "dept" block in a LOOP):
    DECLARE
    rg_id_l RECORDGROUP;
    rg_name_l VARCHAR2 (30) := 'DEPT';
    row_count_l NUMBER;
    rgc_id_l GROUPCOLUMN;
    pl_id_l PARAMLIST;
    pl_name_l VARCHAR2 (30) := 'PARAM_LIST';
    BEGIN
    rg_id_l := FIND_GROUP (rg_name_l);
    IF NOT ID_NULL (rg_id_l) THEN
    DELETE_GROUP (rg_id_l);
    END IF;
    rg_id_l := CREATE_GROUP (rg_name_l);
    rgc_id_l := ADD_GROUP_COLUMN (rg_id_l, 'deptno', NUMBER_COLUMN);
    rgc_id_l := ADD_GROUP_COLUMN (rg_id_l, 'dname', CHAR_COLUMN, 14);
    rgc_id_l := ADD_GROUP_COLUMN (rg_id_l, 'loc', CHAR_COLUMN, 13);
    GO_BLOCK ('dept');
    FIRST_RECORD;
    row_count_l := 0;
    LOOP
    row_count_l := row_count_l + 1;
    ADD_GROUP_ROW (rg_id_l, row_count_l);
    SET_GROUP_NUMBER_CELL (rg_name_l || '.deptno', row_count_l, :dept.deptno);
    SET_GROUP_CHAR_CELL (rg_name_l || '.dname', row_count_l, :dept.dname);
    SET_GROUP_CHAR_CELL (rg_name_l || '.loc', row_count_l, :dept.loc);
    EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';
    NEXT_RECORD;
    END LOOP;
    IF row_count_l = 0 THEN
    MESSAGE ('Nothing to print'); PAUSE;
    RETURN;
    END IF;
    pl_id_l := GET_PARAMETER_LIST (pl_name_l);
    IF NOT ID_NULL (pl_id_l) THEN
    DESTROY_PARAMETER_LIST (pl_id_l);
    END IF;
    pl_id_l := CREATE_PARAMETER_LIST (pl_name_l);
    ADD_PARAMETER (pl_id_l, 'Q_1', DATA_PARAMETER, rg_name_l);
    RUN_PRODUCT (REPORTS, 'REC_GROUP_REPORT', SYNCHRONOUS, RUNTIME, FILESYSTEM, pl_id_l, NULL);
    END;
    This works in Forms 6i. In Forms 9i we must use RUN_REPORT_OBJECT instead of RUN_PRODUCT
    (see Oracle MetaLink document 110495.1 "Passing a Record Group to Reports Using RUN_REPORT_OBJECT").
    Regards,
    Zlatko Sirotic

  • How to select a row from duplicate set of records?

    I want to select a row from a duplicate set of records.
    below is the explanation of my requirement.
    select * from test_dup;
    COL_BILL     COL_SERV     COL_SYS
    b1     s1     c
    b1     s1     g
    b1     s2     c
    b1     s2     g
    b2     s2     g
    b2     s3     c
    b2     s3     g
    b3     s3     c
    Here what I want is, for a distinct col_sys if col_bill and col_serv is same then I need the row where col_sys='c'
    from the above result set I need the following:
    b1     s1     c
    b1     s2     c
    b2     s3     c
    I am using the following SQL query which is giving me the correct result set. But it will hamper the performance because there are total 45 columns in the table and total volume is around 50 million.
    select * from test_dup where col_bill||col_serv in (
    select col_bill||col_serv from (
    select col_bill,col_serv,count(*) from test_dup
    where col_sys in ('c','g')
    group by col_bill,col_serv having count(*) >1)) and
    col_sys='c';
    Can anyone please provide me the optimize SQL query for the same.

    Hi,
    Another way,
    SQL> with test_dup
    as
         select 'b1' col_bill, 's1' col_serv, 'c' col_sys from dual union all
         select 'b1', 's1', 'g' from dual union all
         select 'b1', 's2', 'c' from dual union all
         select 'b1', 's2', 'g' from dual union all
         select 'b2', 's2', 'g' from dual union all
         select 'b2', 's3', 'c' from dual union all
         select 'b2', 's3', 'g' from dual union all
         select 'b3', 's3', 'c' from dual
      select col_bill, col_serv, min(col_sys) col_sys
        from test_dup
       where col_sys in ('c', 'g')
    group by col_bill, col_serv
      having count( * ) > 1
         and count(nullif(col_sys, 'g')) > 0;
    CO CO C
    b1 s1 c
    b2 s3 c
    b1 s2 c
    3 rows selected.Regards
    Peter
    Edited by: Peter on Feb 18, 2009 1:10 AM
    - Added test data, thanks Karthick

Maybe you are looking for