Help find the Last run date from previous month

Hi all
I am stuck trying to find the Last Run Date from the previous month.
select distinct(date_ran) from TABLE X where date_ran like '%/11-%' order by date_ran desc gives
"03/30/11-06:19
"03/25/11-03:01
"03/24/11-03:00
"03/23/11-03:00
"03/22/11-03:00
"03/21/11-03:00
"03/18/11-03:00
"03/17/11-00:00
"03/16/11-06:31
"02/15/11-07:42
"02/15/11-06:00
"02/14/11-08:19
Here the result I am trying to acheive is 02/15/11-07:42 ;Note the column date_ran is a VARCHAR2(255) and not a TIMESTAMP
I tried
select ADD_MONTHS(to_date(max(date_ran), 'MM/DD/YYYY-HH24:MI'),-1)
from daily_tests_a
where date_ran like '%/11-%'
order by date_ran desc
which returns 2/28/0011 6:19:00 AM and that is not the result I am looking for
Regards
SMK

Welcome to the forum!
user2931503 wrote:
Hi all
I am stuck trying to find the Last Run Date from the previous month.
select distinct(date_ran) from TABLE X where date_ran like '%/11-%' order by date_ran desc gives
"03/30/11-06:19
"03/25/11-03:01
"03/24/11-03:00
"03/23/11-03:00
"03/22/11-03:00
"03/21/11-03:00
"03/18/11-03:00
"03/17/11-00:00
"03/16/11-06:31
"02/15/11-07:42
"02/15/11-06:00
"02/14/11-08:19
Here the result I am trying to acheive is 02/15/11-07:42 ;Note the column date_ran is a VARCHAR2(255) and not a TIMESTAMPThat's a very bad idea. Points in time should always be stored in DATE (or maybe TIMESTAMP) columns. If not, you're going to waste resources converting them to DATEs whenever you need them to behave like DATEs, and risk run-time errors because of bad data.
Normally, the "previous" month means the month before the current month. In April, the previous month is March.
By "previous" month, do you mean the 2nd latest month in the table? That is, this data contains data from February and March, 2011; March 2011 is the latest of those months, February 2011 is the next-to-last, and so is that why you want a date from February?
I tried
select ADD_MONTHS(to_date(max(date_ran), 'MM/DD/YYYY-HH24:MI'),-1)
from daily_tests_a
where date_ran like '%/11-%'
order by date_ran desc
which returns 2/28/0011 6:19:00 AM and that is not the result I am looking for
Regards
SMKTry this:
WITH   got_real_date   AS
     SELECT     TO_DATE ( SUBSTR (date_ran, 1, 14)
               , 'MM/DD/RR-HH24:MI'
               )     AS real_date
     FROM     table_x
--     WHERE     ...     -- If you need any filtering, put it here
SELECT     TO_CHAR ( MAX (real_date)
          , 'MM/DD/RR-HH24:MI'
          )     AS last_date
FROM    got_month_num
WHERE     real_date     < (
                           SELECT  TRUNC (MAX (real_date), 'MONTH')
                     FROM    got_real_date
;Edited by: Frank Kulash on Apr 5, 2011 3:59 PM

Similar Messages

  • How to find the last run date of the report..

    please any one one help me
    how to find last run date of the report...
    for example if my report is zgrir...if i am exuted in last week
    if want to find when it executed
    last run date is req
    please any one help me...

    The trasaction stat is limited because i want all the execution date even if it is 3 years ago.
    I have tryied the transaction st03 but it is limited to 3 months ago.
    check transaction STAT and it's report RSSTAT00.
    U can copy RSSTAT00 into ZRSSTAT00 and modify corresponding.
    *& Report ZDSAP *
    REPORT ZDSAP .
    DATA: d_ref TYPE REF TO data,
    d_ref2 TYPE REF TO data ,
    i_alv_cat TYPE TABLE OF lvc_s_fcat,
    ls_alv_cat LIKE LINE OF i_alv_cat.
    TYPES tabname LIKE dcobjdef-name .
    parameter: p_tablen type tabname.
    data: begin of itab occurs 0.
    INCLUDE STRUCTURE dntab.
    data: end of itab.
    FIELD-SYMBOLS : <F_FS> TYPE table,
    <F_FS1> TYPE TABLE,
    <F_FS2> TYPE ANY,
    <F_FS3> TYPE TABLE.
    REFRESH itab.
    CALL FUNCTION 'NAMETAB_GET'
    EXPORTING
    langu = sy-langu
    tabname = p_tablen
    TABLES
    nametab = itab
    EXCEPTIONS
    no_texts_found = 1.
    LOOP AT itab .
    ls_alv_cat-fieldname = itab-fieldname.
    ls_alv_cat-ref_table = p_tablen.
    ls_alv_cat-ref_field = itab-fieldname.
    APPEND ls_alv_cat TO i_alv_cat.
    ENDLOOP.
    internal table build
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING it_fieldcatalog = i_alv_cat
    IMPORTING ep_table = d_ref .
    ASSIGN d_ref->* TO <F_FS>.
    SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <F_FS>.
    LOOP AT <F_FS> ASSIGNING <F_FS2>.
    *your code goes here.
    ENDLOOP.

  • How to get the last run date.

    We intend to develop an incremental data load mapping using this strategy:
    1) The mapping reads the date it was last run from an auxiliary table.
    2) It selects from the source only those rows that were inserted or updated after said date.
    3) Then, a post-mapping process updates the last run date in the auxiliary table, using SYSDATE.
    The problem with this logic is that there is a gap: if the mapping starts running at 1:00 and ends at 2:00, the rows that are inserted in between will never be loaded.
    Is there any way to get the value when the mapping started running? Is there a better way to do this?
    Any help would be appreciated.
    Juan Algaba

    There is always the possibility of some record updates slipping through the crack if you are depending on dates unless you are very carefull. All of the audit tasks that the OWB-generate code performes take time. Any pre- or post- process that needs to run takes time. So which date is the best cuttoff point to equate to "when the last run of the merge (or insert or update) statement completed"?
    Plus, how do you handle reloads if the previous load failed and your mapping had incremental commits?
    Is your source on another server? If so, are the dates in perfect synch? The audit tables populate with sysdate of your runtime schema. Is that the same as the sysdate on your source remote database?
    I would qualify my query to look for all updates since the start of the last run that finished successfully - adjusted if neccesary for sysdate differences if it is on a remote schema. And make sure that your code handles any reloads gracefully in the event that this brings back data that you have already loaded once. .
    Because we use Oracle Streams to load a local staging area, we also have custom code to dump the primary keys of all data changes to utility staging tables while streams is updating the local copy. So, our Person table has an st_Person_delta table that just holds the primary keys that have been updated by Streams since the last ETL run.
    During datamart load we disable the streams apply to stabilize our environment, and join these lists of pk's to their source tables to drive our ETL. So we only select data where Streams has performed an update to the row since our last run. When we are done our ETL, we truncate the primary key staging tables, and then turn streams back on to start loading up our new delta into our staging tables again..
    The ETL gets pretty complex though when many tables join together in one mapping and you need to check all possible source table deltas to see if any of them got updated to determine the delta for a given dimension or fact record, but it works great once you get it all done.

  • How to find the Last modified date and time of a package

    Hi,
    We need a clarification on how to find the Last modified date and time of a package in Oracle. We used the example below to explain our scenario,
    Lets consider the following example
    Let A, B be two packages.
    Package A calls the package B. So A is dependent on B.
    When A is compiled the TIMESTAMP,LAST_DDL_TIME in USER_OBJECTS gets updated.
    Now there a modification in package B so it is compiled. There is no modification in package A.
    Now when the package A is executed the TIMESTAMP,LAST_DDL_TIME in USER_OBJECTS gets updated but we did not make any change in Package A. Now we need to find last modified date and time of the package A . So we can not rely on the TIMESTAMP,LAST_DDL_TIME in USER_OBJECTS . Can u please tell us any other solution to get last modified date and time of the package A .
    Regards,
    Vijayanand.C

    Here is an example:
    SQL> SELECT OBJECT_NAME,CREATED,LAST_DDL_TIME,TIMESTAMP,STATUS FROM USER_OBJECTS
    2 WHERE OBJECT_NAME = ANY('A','B');
    OBJECT_NAM CREATED LAST_DDL_TIME TIMESTAMP STATUS
    A 20-MAY-2004 10:57:32 20-MAY-2004 10:57:32 2004-05-20:10:57:32 VALID
    B 20-MAY-2004 10:58:22 20-MAY-2004 10:59:04 2004-05-20:10:59:04 VALID
    SQL> CREATE OR REPLACE PROCEDURE A AS
    2 BEGIN
    3 NULL;
    4 NULL;
    5 END;
    6 /
    Procedure created.
    SQL> SELECT OBJECT_NAME,CREATED,LAST_DDL_TIME,TIMESTAMP,STATUS FROM USER_OBJECTS
    2 WHERE OBJECT_NAME = ANY('A','B');
    OBJECT_NAM CREATED LAST_DDL_TIME TIMESTAMP STATUS
    A 20-MAY-2004 10:57:32 20-MAY-2004 11:01:28 2004-05-20:11:01:28 VALID
    B 20-MAY-2004 10:58:22 20-MAY-2004 10:59:04 2004-05-20:10:59:04 INVALID
    SQL> EXEC B
    PL/SQL procedure successfully completed.
    SQL> SELECT OBJECT_NAME,CREATED,LAST_DDL_TIME,TIMESTAMP,STATUS FROM USER_OBJECTS
    2 WHERE OBJECT_NAME = ANY('A','B');
    OBJECT_NAM CREATED LAST_DDL_TIME TIMESTAMP STATUS
    A 20-MAY-2004 10:57:32 20-MAY-2004 11:01:28 2004-05-20:11:01:28 VALID
    B 20-MAY-2004 10:58:22 20-MAY-2004 11:01:53 2004-05-20:11:01:53 VALID
    Note that the date under the column 'created' only changes when you really create or replace the procedure.
    Hence you can use the column 'created' of 'user_objects'.

  • How to find the last update date time and user of record field peoplecode

    how to find the last update date time record field peoplecode?
    Thank you.

    One can check the last update date time using the following query
    SELECT LASTUPDDTTM FROM PSPCMPROG WHERE OBJECTVALUE1 LIKE 'RECNAME' AND OBJECTVALUE2 LIKE 'FIELDNAME'

  • How to find the last modified date of a workflow.

    How to find the last modified date of a workflow.
    thanks.

    Hi,
    There is nothing as standard that does this - you could write some code to determine the latest begin_date from each of the workflow tables and assume that this was the last time that the definition changed.
    What you need is something like this:
    select max(wfa.begin_date)
    from   wf_process_activities  wpa
    ,      wf_activities          wfa
    ,      wf_item_types_tl       wit
    where  wpa.activity_item_type = wfa.item_type
    and    wpa.activity_name      = wfa.name
    and    wfa.version            = (select max(version) from wf_activities wfa1 where wpa.activity_item_type = wfa1.item_type and wpa.activity_name = wfa1.name )
    and    wpa.process_item_type  = 'your item type'
    and    wpa.process_item_type  = wit.namewhich I think gives what you want.
    HTH,
    Matt
    Alpha review chapters from my book "Developing With Oracle Workflow" are available on my website:
    http://www.workflowfaq.com
    http://forum.workflowfaq.com
    NEW! - WorkflowFAQ Blog at http://thoughts.workflowfaq.com

  • Find the last run of program

    Hi,
    How to find the last execution time of a program.
    I do not find in ST03.
    Can you please suggest me.
    Thanks
    Hema

    HI Hema,
      Kindly donot open multiple threads on the same question the solution is already provided in this thread. Please close the thread if answered ..
    Re: Find the last run of program
    Regards<
    Santosh

  • How to find the last executed date of any program?

    <<Frequently asked questions. So search>>
    How to find the last executed date of any program?
    is there any system variable or function module?
    Edited by: Matt on Oct 5, 2010 12:48 PM

    check the transaction STAD.
    Prabhudas

  • TS4036 I added Icloud to join my calendar to another person. It erased all history date from previous months. how do I get that data back?

    I added Icloud to join my calendar on my phone to another person. It erased all history date from previous months. how do I get that data back?

    i found the answer to the first part: reboot and keep hold of command+r
    this gave me a list of options
    one of them was to reinstall lion from fresh
    i went for this
    dont know why... but all forum posts i read said u should delete hard disc? theres an option for this
    which is the right option?
    any suggesstion where i go to register new mac would be great
    thanks

  • How to get the last run date of an ISchedulerTask ?

    Hello,
    I have implemented an ISchedulerTask and inside the run method I would like to get a reference to the last timestamp/date that the task was running, any idea how to achieve that?
    Rgds,
    Roy

    Hi
    You can create a custom metadata property and set this property with the date when the Ischedlar task runs.
    So, in your code you can read this property whenever you want to read the previous date.
    Hope this works.
    Thanks
    Puneet

  • Function Module to find the Last Execution date of Back ground Job

    Hi,
    Is there any function module to find the <b>last execution date of back ground job</b>.
    So that I can transfer the data from SAP to Legacy system based on the document creation date should be in between last execution date and current date.
    thanks in advance.
    Eswar.

    Don't know of a function module, but you should be able to use the information in table TBTCO to get the last start date and time of the job you are interested in.

  • To find the Last run details of a program

    Hi Folks,
             I have an SAP query i just want to find out when it is lastly run and by which user? I am unable to find these details in any function module or table. I can check this by using the auto generated program name but i cant get the last run details in trdir table.
    Please sugest me your views towards its solution.
    Thanks in Advance.
    Regards,
    Ravi.

    Hi....
    Try like this....
    data : it TYPE STANDARD TABLE OF sapwlpfnrm.
        CALL FUNCTION 'SAPWL_STATREC_DIRECT_READ'
          EXPORTING
           no_of_records                     = -1
           read_start_date                   = sy-datum
            read_start_time                  = '000000'
            read_end_date                    = sy-datum
            read_end_time                    = '240000'
    *     read_client                       = ' '
           read_username                     = "<give the user name>"
           read_workprocess                  = 'FFFF'
         IMPORTING
           normal_records                    = it     " this table will give you all the transactions run on the given date range
    *   NORMAL_RECORDS_KB                 =
         EXCEPTIONS
           wrong_parameter_combination       = 1
           file_problems                     = 2
           convert_overflow                  = 3
           OTHERS                            = 4
    Regards
    Debarshi

  • How can you find the Last Modified Date of a particular table

    Hi,
    I want to show to the LAST MODIFIED date of a particular table to the user before refreshing the table with new data. Experts please suggest me the way using JDBC-SQL connection.

    There is no generic SQL way for this. It depends completely on the features your DBMS offers. With Oracle you'd need to create column which gets updated in a trigger. I believe MS SQL Server offers a special data type for this, which is updated automatically. I don't know about others.

  • How to find the last executed date ,time and user of the quaery

    Hi,
    How to find the following information of the Query
    1. Where all the place these queries/web template used.
    2. When was it last executed.
    3. Who executed last.
    Regards,
    Hari

    hi Hari,
    you can try table /BI0/APERS_BOD00
    for query, first go to table RSRREPDIR, give field COMPID
    with query technical name and get GENUNIID, then go to table /BI0/APERS_BOD00, field TCTOBJNM = RSRREPDIR-GENUNIID, TCTUSERNM and TCTTIMSTMP -> user name and last executed.
    for web template, give field TCTOBJNM in table /BI0/APERS_BOD00 with web template name.
    hope this helps.

  • Query returns data from previous month. Need to have it return data for the entire year

    This is the part of the query that returns data by month:
    (YEAR(`rereport`.`market_reports_5`.start_date) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)AND MONTH(`rereport`.`market_reports_5`.start_date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH))
    How can I get it to return data for the year.
    TIY

    How about omitting the MONTH part:
    (YEAR(`rereport`.`market_reports_5`.start_date) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

Maybe you are looking for