Get the yesterday or last month data

Hi ,
I've need a small help .
This is the scenario.
If today is 1st feb. so I need to get last month data.
if today is 30 th i need to get the current month data before 30 I mean 29 days data.
I have to do it automatically i mean i need to write case statement in my existing query by using sysdate and i have to get it .
pls help me out . Your help is greatly appreciated.
Thanks & Regards,
madhav.

Haven't tested it, but you could try something like
This gives you last months data if executed on the first day of the month otherwise this months data until the day before today
select *
from my_table
where my_date >= add_months(trunc(sysdate, 'MM'), sign(trunc(sysdate)-trunc(sysdate, 'MM'))-1)
and   my_date <trunc(sysdate)After I read your posting again, I guess you wanted something else
This query now gives you last months data if executed on the first day of the month otherwise the data of the day before today
select *
from my_table
where my_date >= (case when trunc(sysdate) = trunc(sysdate, 'MM') then add_months(trunc(sysdate, 'MM'), -1) else trunc(sysdate-1) end)
and   my_date <trunc(sysdate)Message was edited by:
Jens Petersen

Similar Messages

  • Reg: Getting the latest or last saved data from the table

    Hi,
    I'm having a table, which is getting updated whenever something is saved.
    Now i want to get the latest or last saved details to be displayed or the details of the row with greatest Id.( i.e, the Id. will be greatest for the last saved)
    please help me out with code to do this...
    Thanks & Regards,
    Suresh

    Hi Suresh,
    This could be done either through the webdynpro or the back end function module itself.
    If another field of type date/time is present in the table, u can save the current date and time along with the data in the table, and sort it in descending order of time. so that whenever u refresh the page the latest record is always in the first row,
    if u want to do it through webdynpro, u can also sort the table based on the date so that u get the latest record that was saved.
    Another solution is that u can maintain a serial number sort of thing the table which helps u identify the latest record
    Hope this helps u.
    Regards,
    Poojith M V

  • Need formula in my subreport to get last month date - CR XIr2

    Post Author: olesco
    CA Forum: Formula
    I need to pass the value (#of units) from the subreport to the main report u2013 I know how to do that but my problem is I donu2019t know what formula should I put in my subreport  to get last month date.
    Both main report and subreport have a date parameter (Field link - {?DatePrompt}. What I need is when I fill in the current month date to the main report the subreport should process the last moth date.
    Main report u2013 Date Range (2007-10-1) (2007-10-31) - result  #of units = 22
    u201CRecord Selection Formula Editor
          DateRecd = {@DatePrompt} &#91;i.e. current month&#93;
    Subreport u2013 should have data from last month - result  #of units = 25
    u201CRecord Selection Formula Editor
          DateRecd < {@DatePrompt} &#91;last month&#93;   ??????
    There are   22 3 units this month and   25  units last month.
    Any help is greatly appreciated.

    Post Author: SKodidine
    CA Forum: Formula
    DateRecd in dateadd('m',-1,minimum({@DatePrompt})) to dateadd('m',-1,maximum({@DatePrompt}))

  • Traffic light on the basis of last month

    Hi guys,
    I have a question about the traffic light in the model Visual Composer. I would like to have a traffic light besids a table or graphic that wil be shown the status ( Green, red, yellow!) on the basis of the last month. In the table or in a graphic wil be shown several data of several months. But the traffic light have to respond on the basis of last month. That means that, if the last month exception( in the query) is green, the traffic light also wil be green.
    Can anybody help me please?
    Another question.
    How can i get only two types of order as example in a pie chart? I have seen that in a pie chart you can only add one formula, not two.So!!
    Thanks,
    Regards,
    Esrat

    In the VC model create an Expression Box. Double click on this box to open up its Properties.
    In the control properties window there is tab "Styles", here give Green color to the column 'Style' and in the next column 'Condition' select 'Enter Formula...'
    Select the field and enter the condition.
    Like
    Style      Condition
    Style 1   @CITY == 'Frankfurt'
    Style2    @BANK_CTRY == 'DE'

  • Is it possible to post the Excise invoice previous month date.

    Dear All,
    We want to post a excise invoice with previous month date. Is that possible?
    We have created a billing document (VF01) last month (October) and not created Excise Invoice (J1IIN).
    Now our finance people requirement is to create the excise invoice with last month date.
    Kindly let me know whether it is possible.
    Regards,
    Mullairaja

    Yes quite possible provided your FI period is still open.  Once you execute J1IIN and clicked the tab "Billing", you can see a field Posting Date where you maintain the billing document date itself if FI period is open.
    But from excise point of view, this is wrong due to the fact that excise returns should be submitted on or before 3rd of every month in which case, the excise team would have submitted the returns for October.
    thanks
    G. Lakshmipathi

  • Routine to capture last month data

    Hello Frnds,
    For a Dataload from the datasource Actual Cost Component Split(0CO_PC_ACT_10), we want to capture last month data ,
    we are planning to write a routine in infopackage level,
    using the option 6-ABAP routine, to select the last month data ,
    we have the time characteristics 0FISCPER, At present we managing the load by manually changing the selection for last month every time ,
    It would be a great help if anybody can show a sample code to select last month data,
    Thanks,
    saty

    If 'last month data' for you is equivalent to 'actual month data', post this code (corrected) into your IPACK dynamic selection:
    DATA: zyear type /BI0/OIFISCYEAR,
    ______zperiod type /BI0/OIFISCPER3,
    ______zfiscper type /BI0/OIFISCPER.
    CLEAR: zyear,
    _______Zperiod,
    _______zfiscper.
    MOVE sy-datum+0(4) to zyear.
    MOVE sy-datum+4(2) to zperiod.
    concatenate  zyear zperiod into zfiscper.
    l_t_range-iobjnm = '0FISCPER'.
        l_t_range-fieldname = '/BI0/FISCPER'.
        l_t_range-sign = 'I'.
        l_t_range-option = 'EQ'.
        l_t_range-low  = zfiscper.
        l_t_range-high = zfiscper.
        APPEND l_t_range.
    Message was edited by: Claudio Caforio

  • Function module to get the next new 12 months of a year

    Hi All,
    I have a requirement to get the next new 12 months of a year from the current month , i.e. if my current month is June 2009 , I need to get June 2009, July 2009,...................., May 2010 .
    Does anybody know if there is any function module for this or is there any logic to implement this .
    Please could someone help me out with this.
    Regards,
    Sushanth H.S.

    Dear Srinivas,
    Have a look at the below code. It works fine. Change according to your req.
    REPORT ztest_notepad.
    DATA:
          month_index TYPE i,
          wa_t015m    TYPE t015m,
          it_t015m    TYPE t015m OCCURS 0 WITH HEADER LINE.
    DATA:
          BEGIN OF it_next12 OCCURS 0,
            months_12 TYPE string,
          END OF it_next12.
    PARAMETERS:
          p_month TYPE num2,
          p_year  TYPE num4.
    START-OF-SELECTION.
      SELECT * FROM t015m INTO TABLE it_t015m WHERE spras = sy-langu.
      READ TABLE it_t015m INTO wa_t015m WITH KEY monum = p_month.
      IF sy-subrc = 0.
        month_index = sy-tabix.
        LOOP AT it_t015m INTO wa_t015m FROM month_index TO 12.
          CONCATENATE wa_t015m-monam p_year INTO it_next12-months_12 SEPARATED BY '-'.
          APPEND it_next12.
          CLEAR  it_next12.
        ENDLOOP.
        p_year = p_year + 1.
        LOOP AT it_t015m INTO wa_t015m FROM 1 TO month_index.
          CONCATENATE wa_t015m-monam p_year INTO it_next12-months_12 SEPARATED BY '-'.
          APPEND it_next12.
          CLEAR  it_next12.
        ENDLOOP.
      ENDIF.
      LOOP AT it_next12.
        WRITE:/ it_next12-months_12.
      ENDLOOP.
    Thanks
    Venkat

  • Does ODI keeps the record of last run date of interface?

    Target:Oracle
    Source:MS SQL
    ODI:11g
    My requirement is I have a source table, Whatever operations performed on that (like insert,update etc) table, I want to load those records into the target table. For that I have created an Interface which runs daily at 6 PM.While loading, I have put one filter which loads only those data which got inserted/updated on current date(GETDATE()).Suppose the case, If my ODI has been down(because of any reason) since 3 days. In this case I have no option to load the records who got changed in that three days. On the fourth day I start the ODI then, how can I get data which got changed in last three days.
    Is there any place where ODI keeps the record of last run date or something of interface ?
    If I use CDC in that case, once the ODI down then the journalism can not able to keep the changed data info.
    How can I load the changed data into the target.?
    Thanks,
    Shrinivas

    If you have a date column in source and target , I guess you might be having a you are using date , you can use a filter and write the expression like this
    Source_date > (select max(date_created/update) from schema.target_table)
    I have validated this expression and it validated by ODI , I did not try running it , please give it a shot
    Suresh

  • Reg:get the user's Last LogoutDate in UME

    Hi Guys,
              Please let me know, if possible to get the user's Last LogoutDate in UME Database or how to find the user's who have in online or offline in portal.
    Thnaks & Regards
    Vijaykumar.S

    Hi,
    I think the problem you will face here is that a user doesn't have to "logout" of the portal. They can just close the browser window, but that should at least end the session. I know in the portal you can see current sessions but I don't think this data is saved anywhere....
    This might help: http://help.sap.com/saphelp_nw04/helpdata/en/03/37dc4c25e4344db2935f0d502af295/frameset.htm
    Also this other post might help you: How to view Logged in User's sessions
    Hope this helps, I would be interested to know when you find a solution.
    BRgds,
    Simon
    Edited by: Simon Kemp on Feb 14, 2010 4:30 PM

  • Logic to build report to get the stock on a particular date

    Dear Guru's,
    We are trying to build a report for getting the stock on a particular date. It is not possible to copy MB5B that option is ruled out. We have also tried to get the data from MBEWH but that is also  not helping as the table is not updated for all the periods.
    Please advice
    Thanks,
    Sam

    Dear Sameer,
    You can copy MB5B report and can modify as per your reuirement.
    If you want get stock a paticular date.It is hard to get, why because you have to fetch all the Material documents
    and you have to use MBEW table to get the current date stock and you have to do add/subtract from calculated stock.
    Due to this there will performance issues also.
    So try to copy MB5B and change as per your requirement.
    regards
    Subhash

  • MacPro backed up to Time Machine, added Mac Mini now get "The backup disk image "/Volumes/Data/Jerry Booher's MacBook Pro.sparsebundle" is already in use." error when Mac Pro tries to back up

    MacPro backed up to Time Machine, added Mac Mini now get "The backup disk image “/Volumes/Data/Jerry Booher’s MacBook Pro.sparsebundle” is already in use." error when Mac Pro tries to back up

    It is standard Mountain Lion error due to the networking ability which is comparable to wet string. (actually that was lion.. it dried out some with Mountain Lion.. higher in the hills perhaps!!)
    See C12 and C17
    http://pondini.org/TM/Troubleshooting.html
    But many people are suffering the same issue..
    And the above is even a little out of date.. you might need to do a reset to the TC.
    Welcome to Apple's beta program for everyone.

  • How to get the previous state of my data after issuing coomit method

    How to get the previous state of some date after issuing commit method in entity bean (It should not use any offline storage )

    >
    Is there any way to get the state apart from using
    offline storage ?As I said the caller keeps a copy in memory.
    Naturally if it is no longer in memory then that is a problem.
    >
    and also what do you mean by auditlog?
    You keep track of every change to the database by keeping the old data. There are three ways:
    1. Each table has a version number/delete flag for each record. A record is never updated nor deleted. Instead a new record is created with a new version number and with the new data.
    2. Each table has a duplicate table which has all of the same columns. When the first table is modified the old data is moved to the duplicate table.
    3. A single table is used which has columns for 'table', 'field', 'data' and 'activity' (update, delete). When a change is made in any table then this table is updated. This is generally of limited useability due to the difficulty in recovering the data.
    All of the above can have a user id, timestamp, and/or additional information which is relevant to the data being changed.
    Note that ALL of this is persisted storage.
    I am not sure what this really has to do with "offline storage" unless you are using that term to refer to backed up data which is not readily available.

  • Function module to get the posting period based on date

    Hi to all,
    Is there any function module to get the posting period based on date?
    Regards,
    Nagesh

    hi,
    CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
          EXPORTING
            I_GJAHR        = GV_GJHAR
            I_PERIV        = GC_24
            I_POPER        = GV_POPER
          IMPORTING
            E_DATE         = S_FKDAT-LOW
          EXCEPTIONS
            INPUT_FALSE    = 1
            T009_NOTFOUND  = 2
            T009B_NOTFOUND = 3
            OTHERS         = 4.
        IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
        CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
          EXPORTING
            I_GJAHR        = GV_GJHAR
            I_PERIV        = GC_24
            I_POPER        = GV_POPER
          IMPORTING
            E_DATE         = S_FKDAT-HIGH
          EXCEPTIONS
            INPUT_FALSE    = 1
            T009_NOTFOUND  = 2
            T009B_NOTFOUND = 3
            OTHERS         = 4.
        IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
    ags.

  • Get the year out of a date

    I have a date '12/02/1989'. how do i get the year out of this date.
    or take a sysdate and get the year out of it.
    Thanks

    this?
    SQL> ed
    Wrote file afiedt.buf
      1  SELECT EXTRACT (YEAR FROM TO_DATE('12/02/1989','mm/dd/yyyy')) year
      2* FROM dual
      3  /
          YEAR
          1989
    or this/
    SQL> ed
    Wrote file afiedt.buf
      1  SELECT to_char( TO_DATE('12/02/1989','mm/dd/yyyy'),'YYYY') year
      2* FROM dual
    SQL> /
    YEAR
    1989too late
    Message was edited by:
    devmiral

  • HT2513 how do you get the sidebar with three months of just calendar to turn on-is this feature gone?

    how do you get the sidebar with 3 months of calendars on the left?  Is this feature gone?

    Im sorry but I figured it out now. I hate when you figure something out right after you do something extreme like signup for a profile here and post a question. Well to those who want the answer all in one shot there are 2 solutions for me.
    1. Make sure Safari is updated completely. You can check by clicking SAFARI> ABOUT SAFARI
    Safari 5.0.5 gave me this problem but the new update is 5.1.2
    2.Glims - Free ad on for Safari which enables you to view you window in COMPLETE full screen at all times, as well as maximise your window to fill all empty space (makes so you dont have to worry about accidentally clicking on your desktop which I do all the time lol). You can use this option once Glims is installed simply by clicking on
    SAFARI> Full Screen
    or
    SAFARI> Maximise Window Size
    By doing Full Screen mode you can then click on the full screen capability on the website you are on

Maybe you are looking for

  • LaserJet 2100 Paper Feed Issue

    Our company has an HP LaserJet 2100 printer. The problem is every 10 pages or so, the paper will feed through crooked causing the print to be off center and the edge to become crinkled. I replaced the paper with a different ream and a different stock

  • Call RFC from DELPHI Windows Services Program

    Hi all, Are there any way to call RFC from DELPHI Windows Services Program? Best regards. Munur EBCIOGLU

  • SAP Modules Description

    Hi all, Might you explain to me in two lines in order that they are these modules? And if you know it which are the typical transactions codes that are in use in them? FM, SD, WM, BC, BI, CS and PS Thanks !

  • Screen problem in bdc

    hi while making recording for transaction ct04 subscreen is not coming , i need to check two checkboxes on that subscreen while recording but not able to do so can i call that screen manually , if yes please send me the code for that. helpful answers

  • Creative Suite 4, Windows 7 64bit will not run second installation disk

    Hello, I hope someone can help me or point me in the right direction. I just upgrade my PC to Windows 7 on a freshly formatted hard drive and I can't seem to be able to install the second installation disc of  CS4. I install the first disc fine but w