Selecting max date for specific 'operation' code

I have the following scenario: a history table that keeps track of the 'operation' and the date of the operation. For example, the operation field can have a code of U (for update), C (for closed), O (for re-opened), A (for approved), etc.
The goal of this history table is to keep track of all of the modifications made. Hence, a particular record of interest can have more than one 'U' operation documented, C operation, etc.
How can I choose the max date for each operation.
I was diong the following in my PL/SQL:
BEGIN
SELECT operation_code, o_date, user INTO lv_operation_code, lv_date, lv_user FROM table1 WHERE unique_id = pv_id AND operation_code = U' AND o_date = (SELECT max(o_date) FROM table1 WHERE unique_code = pv_id);
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END;
I then have another begin statement for the 'C' operation, etc.

Hi,
OraclePolzovatel wrote:
... I was diong the following in my PL/SQL:
BEGIN
SELECT operation_code, o_date, user INTO lv_operation_code, lv_date, lv_user FROM table1 WHERE unique_id = pv_id AND operation_code = U' AND o_date = (SELECT max(o_date) FROM table1 WHERE unique_code = pv_id);
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END;
I then have another begin statement for the 'C' operation, etc.Are you sure that's what you're doing? There seem to be errors, such as unmatched quotes.
Instead of doing a single SELECT with something like "operation_code = 'U'" in the WHERE-clause, you could write a cursor with "GROUP BY operation_code".

Similar Messages

  • Select Max record for the report

    Post Author: ROMZILBER
    CA Forum: WebIntelligence Reporting
    Hello,
    Here is our problem we have history data on a table like
    Example
    Data:
    11111   bbb       12/31/2004
    11111   nnn       12/31/2005
    11111   ddd       12/31/2007
    On a report we only need to display the most current record (based on a date).
    11111   ddd       12/31/2007
    How can we do that, we have try to create subquery but it does not allowed to enter logic for the max date for the same id.  So we are kind of stuck, I am more then sure this would be a very common conditions specially for data warehousing.
    we are on Oracle 10g
    Thank you for all your help.

    Post Author: ROMZILBER
    CA Forum: WebIntelligence Reporting
    To create a view is not a problem, supporting it is a different story
    But we have find a solution, you were correct about the filter.  I just did not know you can put the whole subselect in a  filter
    but here is a logic for the filter if someone would come up with the same problem
    tablename.NNNN_PROOF_DT = (SELECT MAX(X.NNNN_PROOF_DT) FROM tablename X  WHERE tablename.NNNN_CLAIM_NUMBER = X.NNNN_CLAIM_NUMBER AND   tablename.NNNN_LINE_CD = X.NNNN_LINE_CD)
    please let me know if you have any questions.
    sorry I am new to this so please do not take any offense

  • 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
    ;

  • How to reset data for the company code 1000

    Hi Gurus,
    I am practicing SAP SD on a sandbox server as am learning it.
    But i see that the standard data for the company code 1000 has been altered by previous users and most of the standard setttings have been changed.
    Due to this am having a lot of issues while configuring a new company code by copying it from 1000.
    Please help me reseting the data for the company code 1000 so that it will be easier for customizing and learning.
    Regards,
    Harish

    Hi Harish,
    Follow the step given below
    SPRO --> Enterprise Structure --> Definition --> Financial Accounting --> Edit, Copy, Delete, Check Company Code
    A pop screen will appear which will give you two options
    1)  Copy, delete, check company code
    2)  Edit Company Code Data
    Select option one
    On next screen --> Click at " Check org. object" or press F8 --> It will ask your company code --> enter your company code 1000 --> Enter
    It will check all the related table and if it find any discrepency
    then it will show you one pop up screen
    Errors in
    foreign key dependencies
    Do you want the error log
    displayed now?
    Click at Display now --> correct all the fields which are wrongly maintained.
    Hope this helps
    Regards,
    MT

  • Download SC data for perticular company code

    Hi ,
    Can any one help how to get sc data for perticular company code, any funcation module or report available ?
    we know that from table BBP_PDBEI we can get, we want other than that any option available.
    Thanks
    prasad.s

    Hi
    No standard report available. If you want it, you can modify the report BBP_BW_SC4, to include company code in selection parameter, with relevant logic. Else, as suggessted in the thread chain, build SAP query.
    R/Reddy.

  • 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

  • "Print report REKORD 80 has not selected any data for correspondence SAP18"

    When executed FBCJ transaction click the "print cash journal" button then appears  the following message "Print report REKORD 80 has not selected any data for correspondence SAP18"
    What is the procedure for to fix error?
    Best regards
    John

    HI,
    John.
    please refer the following link.
    correspondence type
    Regards,
    satish

  • Export data for specific period through Data Pump

    Hi,
    I've a specific requirement to take the dumps of some tables for specific time period. like between last 10 days like 01-JAN-11 to 10-JAN-11. How can I acommplish this. For Documentation what I read is that we can export the data for specific period of thie by either setting FLASHBACK_SCN or FLASHBACK_TIME parameter in expdp command but this is point in time export not for the specific time export.
    Please guide me how can export between the specific time. like between 1-JAN to 10-JAN
    Regards,
    Abbasi

    export between the specific time. like between 1-JAN to 10-JANYou need to clarify your requirements. Data is always "at a point in time". I can see data as at noon of 01-Jan. I can see data as at noon of 10-Jan. What would I mean by data "between" 01-Jan and 10-Jan ?
    Say the table has 5 rows on 01-Jan :
    ID    VALUES
    1      ABC
    2      DEF
    3      TRG
    4      MXY
    5     DEW2 Rows "6-GGG" and "7-FRD" were inserted on 02-Jan.
    2 Rows "2" and "3" were updated from "DEF" and "TRG" to "RTU" and "GTR" on 03-Jan.
    1 Row "5-DEW" was deleted on 09-Jan.
    2 Rows "8-TFE" and "9-DZN" were insereted on 09-Jan.
    Can you tell me what is the "data between 01-Jan and 10-Jan" ?
    (the above example actually happens to have an incrementing key column "ID". Your table might not even have such an identifier column at all !)
    Hemant K Chitale
    Edited by: Hemant K Chitale on Jan 10, 2011 5:23 PM

  • SMW00 separate action for specific error-code

    Hello,
    I know transaction SMW00 to send emails for bdoc-errors. Can I take seperate action for specific error-codes from specific organisational units?
    Thanks for helping,
    Bart

    Hi Bart,
    Using standard action handler it is not possible but one other option is to take a copy of RSMW0_CONFIG_ERRORHANDLER and enhance it to send actions based on organisational units.
    Rregards,
    Surendar

  • SQL Command to select MAX(date) & Max(time)

    My am having a really hard time getting a sql command to return data with the max(date) & max(time) combination. I think I need a sub query but can not figure it out. I have looked all over the internet but still don't understand it. Below is my command which returns the max date & max time but they are not from the same row of data. Please help.
    SELECT  "labor"."order-no", "labor"."oper-no", MAX("labor"."end-date") AS myDate, Max("labor"."end-time") AS myTime
    FROM   "E940LIVE"."PUB"."tm-log" "labor"
    WHERE  "labor"."order-no"='73153-bc' AND "labor"."company"='01'
    GROUP BY  "labor"."order-no", "labor"."oper-no"

    Progress does not support the DATEADD function. Waht if I forget the number is time and look at it just as a number. Here is my data and what I have tried (again I don't understand the multiple select concept yet).
    Data
    oper-no   end-date    end-time
      20      2/2/2010     41,975
      30      2/3/2010     45,906
      30      2/16/2010    32,941
      40      2/4/2010     46,099
      40      2/4/2010     50,227
      40      2/4/2010     59,466
      40      2/4/2010     62,024
      40      2/16/2010    43,838
      60      2/17/2010    32,679
      90      2/25/2010    35,270
    SQL Command
    SELECT a."oper-no", a."end-time", a."end-date"
    FROM   "E940LIVE"."PUB"."tm-log" a, (SELECT "end-time", max("end-date") AS max_date FROM "E940LIVE"."PUB"."tm-log" WHERE  "order-no"='73153-bc' AND "company"='01' GROUP BY "end-date", "end-time") b
    WHERE  a."end-time" = b."end-time" AND a."end-date" = b.max_date AND a."order-no"='73153-bc' AND a."company"='01'
    Result
    oper-no   end-date     end-time
      20      2/2/2010      41,975
      30      2/3/2010      45,906
      40      2/4/2010      50,227
      40      2/4/2010      46,099
      40      2/4/2010      59,466
      40      2/4/2010      62,024
      30      2/16/2010     32,941
      40      2/16/2010     43,838
      60      2/17/2010     32,679
      90      2/25/2010     35,270
    Desired Result
    oper-no   end-date    end-time
      20      2/2/2010     41,975
      30      2/16/2010    32,941
      40      2/16/2010    43,838
      60      2/17/2010    32,679
      90      2/25/2010    35,270
    Thanks for any and all help!
    Wayne

  • Select MAX Date

    I have the following recordset that includes a Patient Identification Number along with a Date of Service:
    PatientID  DOS
    ======  ======
    11111      1/1/2015 
    11111      1/5/2015
    33333      1/3/2015
    22222      1/2/2015
    11111      2/1/2015
    22222      1/1/2015
    11111      1/2/2015
    33333      2/10/2015
    11111      2/11/2015
    22222      1/1/2015  
    I need a query that shows the MAX DOS for each patient.  For example:
    PatientID  DOS
    ======  ======
    11111      2/11/2015
    22222      1/2/2015
    33333      2/10/2015
    Is this possible?
    Thanks.

    t1 and t2 is alias for table
    SELECT
    PatientID ,( select max ( DOS ) from Patient as t2 where t2 . PatientID = t1.PatientID ) DOS
    FROM
    Patient as t1
    group by PatientID
    I only have one table in select and subselect
    Uma imagem vale mais do que mil palavras, mas ocupa 3 mil vezes mais espaço em disco

  • HR Form do not select any data from specific Period

    Hi All
    I am facing issues on the HR FORMS for Brazil related to the Remunaration Statement
    When I try to select any employee from a specific period (before April 2012), the system does not select any data.
    From April 2012 until the current period and I could select the data and print the Form
    I do not believe that is related to the Master data from the Employee, since it is always related to the same period, I guess it is on the HR Form configuration, retricting the period anywhere, but I could not find it
    do you know any idea on how to fix it ?
    Regards

    Hi Steve,
    In SQL Server Analysis Services, we can hide or disable hierarchy level by using
    AttributeHierarchyEnabled property, however, when this property is set to false, this level will not appear no matter if contain data or not. In your scenario, you want to hide the hierarchy level dynamically, right? As Aleksandr
    said, I am afraid there is no such a method to achieve it.
    If you have any concern about this behavior, you can submit a feedback at
    http://connect.microsoft.com/SQLServer/Feedback and hope it is resolved in the next release of service pack or product. Your feedback enables Microsoft to make software and services the best that they can be, Microsoft might consider to add this feature
    in the following release after official confirmation.
    Regards,
    Charlie Liao
    If you have any feedback on our support, please click
    here.
    Charlie Liao
    TechNet Community Support

  • MIN and MAX date for each range

    Hi folks,
    I´ve got the following problem:
    Given a table
    create table t as select 'AT' OM_LANDTEXT, '12345' OM,
                             to_date('01-JAN-2004', 'DD-MON-YYYY') datum from dual
                             union
                             select 'AT' OM, '12345' OM_LANDTEXT,
                             to_date('02-JAN-2004', 'DD-MON-YYYY') datum from dual
                             union
                             select 'AT' OM, '12345' OM_LANDTEXT,
                             to_date('03-JAN-2004', 'DD-MON-YYYY') datum from dual
                             union
                             select 'AT' OM, '12345' OM_LANDTEXT,
                             to_date('05-JAN-2004', 'DD-MON-YYYY') datum from dual
                             union
                             select 'AT' OM, '12345' OM_LANDTEXT,
                             to_date('06-JAN-2004', 'DD-MON-YYYY') datum from dual
                             union
                             select 'AT' OM, '12345' OM_LANDTEXT,
                             to_date('01-FEB-2004', 'DD-MON-YYYY') datum from dual
                             union
                             select 'AT' OM, '12345' OM_LANDTEXT,
                             to_date('02-FEB-2004', 'DD-MON-YYYY') datum from dual
                             union
                             select 'AT' OM, '12345' OM_LANDTEXT,
                             to_date('03-FEB-2004', 'DD-MON-YYYY') datum from dual;
    SQL> select * from t;
    OM OM    DATUM
    AT 12345 01-JAN-04
    AT 12345 02-JAN-04
    AT 12345 03-JAN-04
    AT 12345 05-JAN-04
    AT 12345 06-JAN-04
    AT 12345 01-FEB-04
    AT 12345 02-FEB-04
    AT 12345 03-FEB-04
    8 rows selected.I need to have the first and last date for om and om_landtext for each date range (where "date range" means a set of consecutive dates with no gaps).
    So the ouput should be
    OM OM_LANDTEXT DATVON DATBIS
    AT 12345     01-JAN-04 03-JAN-04
    AT 12345     05-JAN-04 06-JAN-04
    AT 12345     01-FEB-04 03-FEB-04Any ideas...?
    Thanks for your help!
    Best regards,
    Gerd
    Message was edited by: Gerd
    Sorry, I forgot to mention this should be done in pure SQL if possible.
    [email protected]

    This is the plodding, methodical approach I've always taken, which leaves me somewhat in awe of Rod West's solution.
    SELECT om_landtext,
           om,
           MIN(datum) AS min_datum,
           MAX(datum) AS max_datum
      FROM (
    SELECT om_landtext,
           om,
           datum,
           prev_datum,
           COUNT(
             CASE
               WHEN prev_datum IS NULL THEN 'x'
               WHEN prev_datum != datum-1 THEN 'x'
               ELSE NULL
             END
           ) OVER (PARTITION BY om_landtext, om ORDER BY datum) AS grp
      FROM (
    SELECT om_landtext,
           om,
           datum,
           LAG(datum) OVER (PARTITION BY om_landtext, om ORDER BY datum) AS prev_datum
      FROM t
    GROUP BY
           om_landtext,
           om,
           grp;null

  • Report to show data for specific MD

    Hello,
    I am racking my brain thinking of a way to do this...
    I have some specific masterdata for example Product 1,2,3...10 and i also have a cube where any Actual & target sales are recorded
    I need a way of producing a report whereby the report shows ALL products and any data relevant from the cube...
    ie  if there is a product where there is no data for actuals or targets then the report will still show a line but with blanks in the KF.
    (right now, if there are no actuals or targets, that product is ommited from the report, I need to be able to see that product and the fact that there is no data for it in the cube)
    any ideas?
    thanks
    BW_ER

    Hi,
    There are multiple ways of achieving what you want.
    1) You can do as proposed and create an infoset and then you can use and outer join on the master data. This way all master data records are displayed independently of whether they have any transactions in the infocube when you create a query
    2) You can create a multiprovider on your master data and your infocube and then in the mapping of the fields, specify that you want the e.g. 0MATERIAL to come from  your master data
    Hth,
    Jacob

  • How to upload the line item data for the T-CODE CO12 by using LSMW

    Hi ALL
    i have to upload some data using the t-code CO12 by LSMW. can anybody help me where and what code i have to write to upload the multiple line-items in that.
    Thanks in advance.

    i think this follows the rule for BDC with table control, can you please give me some example code and also the step number where i have to write the code for uploading the multiple line items.
    thanks in advance !

Maybe you are looking for

  • My friend's iPhone won't play my music I bought from the iTunes Store.

    My friend has an iPhone 5 with music from his laptop. His laptop is authorized to play music I purchase from the iTunes store, but for some reason his phone won't play those songs. Can somebody explain why, and help me get his iPhone to play those so

  • Error while debugging AIR for IOS app

    I get the following error when attempting to debug my AIR-IOS app on an IPad 2. The weird thing is that the logfile mentioned does not exist. Any ideas? - Abey # A fatal error has been detected by the Java Runtime Environment: #  EXCEPTION_UNCAUGHT_C

  • I restored my laptop to an ealier date and lost my private browsing capability

    My private browser selection on the tools dropdown is grayed out. Mozilla 3.6.10 was reloaded. It still does not work.

  • Conc request error

    Hi Hussain, In Concurrent request log files i found below information. "Cause: AFPRSP failed due to ORA-02049: timeout: distributed transaction waiting for lock" I have tried to find out the locks but not locks i found. Any resoulution for this issue

  • Transaction Canceled 15 100 ( )

    Dear gurus, I am gettingthis errro in sm21.  my environment is ECC 6.0 DB2 Windows 2003 Transaction Canceled 15 100 ( ) The transaction has been terminated.  This may be caused by a termination message from the application (MESSAGE Axxx) or by an err