How to select last year's first day

Hi friends,
How to get the last year's first day using sysdate as on sysdate
this gives the current year's start date
I need last year's start date like 01-jan-2010 as on sysdate
thanks

Another:
SQL> select trunc(sysdate-365.25,'YYYY') from dual;
TRUNC(SYSDATE-365.25
01-JAN-2010 00:00:00Note: the .25 accounts for this query being run on the last day of a leap year e.g.
SQL> select trunc(date '2012-12-31'-365.25,'YYYY') from dual;
TRUNC(DATE'2012-12-3
01-JAN-2011 00:00:00Edit: Note, this still isn't completely accurate and could give a wrong result. Better solution is to use the add_months function.
Edited by: BluShadow on 06-Apr-2011 11:55

Similar Messages

  • How to select last record or first record value in a formula?

    Post Author: d111
    CA Forum: General
    I am using a query in a report that in addition to other columns, has a column of month labels like:
    There are no unique identifiers or sequence fields that can be used.   There is only 4 columns: the label and 3 percent columns.
    Jan07Feb07Mar07Apr07etc.
    I would like to show the range of months I am using in a label on the report showing the last and first records value. like: "Jan07 to Jun07".
    I can not see how to use the functions maximun or minimum since it sorts the months alphabetically.
    I would like to use a formula to just grab the first and last record.  I can't seem to find any information on this anywhere.
    Please advise and thanks.

    Post Author: bettername
    CA Forum: General
    Hmm... I suspect what you actually want is the minimum and maximum dates in the report, rather than the first and last records (even if they do happen to come out in date order). So you need to convert the text dates to real ones, and then pick the min/max values.
    If so, try these:
    Formula "ConvertToDate" (for details section) which converts your text field into a real date - suppress it once placed!:
    //Since you have 2-digit years, this conversion assumes that all your dates are >=year 2000
    numbervar the_month;if left({YourTable.YourField},3) = "Jan" then the_month:=1 elseif left({YourTable.YourField},3) = "Feb" then the_month:=2 elseif left({YourTable.YourField},3) = "Mar" then the_month:=3 elseif left({YourTable.YourField},3) = "Apr" then the_month:=4 else
    //...etc etc you fill in the rest!
    if left({YourTable.YourField},3) = "Dec" then the_month:=12;
    date(tonumber("20"+right({YourTable.YourField},2)), the_month, 1);
    Formula "Show Date Range" (for anywhere on the report) to show the min/max values of the dates;
    totext (minimum({@ConvertToDate})) + " to "+totext(maximum({@ConvertToDate}))
    If, however, you really just want the first and last records, and you want it at the top of your report as a title (eg: in the Report Header), then I can't see how it can be done without using a subreport that looks at the same dataset, but only displays the first and last records (using the formulas below).
    Stick this in the details section, and call it "HoldRecords" and suppress it:
    whileprintingrecords;stringvar first;stringvar last;if recordnumber = 1 then first:={YourTable.YourField}; //if its the first record that crystal is displaying, store it in a variableif recordnumber = count({YourTable.YourField}) then last :={YourTable.YourField} //and again, but for the last record
    Now create another formula, and put it into the report footer:
    evaluateafter({@HoldRecords});stringvar first" to "stringvar last //will display "Jan07 to Apr07"
    NOTE:  if you have the report ordered by anything, this'll throw the record numbering, and therefore the first and last records, therefore... urgh.
    Hope this helps...

  • How to get the date of first day of a week for a given date

    Hi gurus
    can any one say me how to get the date of first day(date of Sunday) of a week for a given date in a BW transformations. For example for 02/23/2012 in source i need to get 02/19/2012(Sunday`s date) date in the result. I can get that start date of a week using  BWSO_DATE_GET_FIRST_WEEKDAY function module. But this function module retrieves me the  start date as weeks monday(02/20/2012) date. But i need sundays(02/19/2012) date as the start date. So it would be really great if anyone sends me the solution.
    Thanks
    Rav

    Hi,
    The simplest way would be to subtract 1 from the date date which you are already getting in transformation routine, but instead of doing that subtraction manually which might need bit of errort, you can simply use another FM to subtract 1 from given date.
    RP_CALC_DATE_IN_INTERVAL
    Regards,
    Durgesh.

  • How to copy last year GL Accounts to this year, with out creation

    HI
    Good evening
    How to copy last year all GL accounts to this year. same configarations.(Not manual creations
    urgently i want please
    Ashok kumar
    [email protected]

    HI
    I dont want copy of Chart of accounts i want copy  GL Accounts
    Thank you
    Ashok kumar
    [email protected]

  • How to get the date of first day of the week

    hi ,
    how can i get the first day of the current week ?
    i have tried the following
    note : my sysdate is 3rd april 2007
    select trunc(sysdate , 'ww') from dual -- 4/2/2007
    select trunc(sysdate , 'w') from dual -- 4/1/2007
    select trunc(sysdate - 4 , 'ww') from dual -- 3/26/2007 -- shld return 25th mar 2007
    select trunc(sysdate - 4 , 'w') from dual -- 3/29/2007 -- shld return 25th mar 2007pls advise
    tks & rgds

    Hi!
    I'm considering MONDAY as the first working day of the current week. And, the code is accordingly --
    SQL> select to_char(sysdate - to_number(decode(to_char(sysdate,'DY'),'TUE','1',
      2                               'WED','2',
      3                               'THU','3',
      4                               'FRI','4')),'dd-mon-yyyy') res
      5  from dual;
    RES
    02-apr-2007Regards.
    Satyaki De.

  • BI Content Variable on 0Calday for first day of the fiscal year and first day of the current month

    Hi Friends,
    In one of my BEx queries, I need to restrict a key figure for 0Calday based on the first day of the current fiscal year. And another key figure for the first day of the current month. Instead of using Customer exit, I hope there is some SAP delivered standard variable for these filters.
    Please let me know if there is anything available for this. Your answers will be highly appreciated.
    Thanks & Regards,
    Ranjan

    Hi Ranjan,
    Please find below standard variables.
    Pls check below link for more.
    Standard Variables in BEX related to Time Charcteristics
    Characteristic
    Variable
    Description
    0CALDAY
    0CWD
    Current Workday (SAP Exit)
    0CALDAY
    0CYTCD
    Cumulated to Current Day (SAP Exit)
    0CALDAY
    0DAT
    Current Calendar Day (SAP Exit)
    0CALDAY
    0DAY_***
    Cumulation of all Values to Key Date (SAP-Exit)
    0CALDAY
    0LYTCLD
    Cumulated to Current Day of Previous Year
    0CALDAY
    0LYTCLD
    Previous Year Cumulated to Current Day (SAP Exit)
    0CALDAY
    0L_DATE
    Last Calendar Date
    0CALDAY
    0P_LY_R
    Comparative Period for Last Year
    0CALDAY
    0P_TY_R
    Period for Current Year up to Yesterday
    0CALDAY
    0S_KDATE
    Key Date Interval for Previous Year (SAP Exit)
    0CALDAY
    0S_KDAY
    Key Date Interval Current Year (SAP Exit)
    Best,
    SATYA.

  • How to add FISCAL YEAR, Period and Day to cube.

    hi,
    I am using SD EXTRACTORS (2LIS_11_VAITM, 2LIS_11_VAKON, 2LIS_12_VCITM and 2LIS_13_VDITM) and directly updating each corresponding ODS and cube.
    All the extractors only have FISCAL VARIANT has the time characteristic. So, all my ODS contains only one time char - fiscal variant and other dates (liek document created date etc. (not a time char)).
    Now, I want to use fiscal period, fiscal year and fiscal day in my cube. I have added these time char in my cube.
    My question:
    1. how to get FISCAL YEAR, FISCAL PERIOD and FISCAL DAY get updated. Do I need to map to document created date in update rules or Do I need to use some functional module.
    Pls note I am bringing only FISCAL VARIANT from R/3 into ODS and then to CUBE.
    PLS REPLY.

    thanks sundar..i got your point..but I have one question
    All the cubes (sales, sales condition and billing) have the sales order number (VBUK-VBELN) and item number (POSNR-VBUK). But info objects used for these fields in sales cube and sales condition cube are same but for billing it is not same.
    Can I combine all cubes (sales order, sales condition, billing) in muliti provider.
    1. Sales order cube (from VAITM)
               Sales order number (VBUK-VBELN) --  (0DOC_NUMBER)
               Sales Item (VBUK-POSNR)              --  (0S_ORD_ITEM)
    Date : Document created date (VBAK-AUDAT) --  0DOC_DATE
    2. Sales Condition cube (from VAKON)
               Sales order number (VBUK-VBELN) --  (0DOC_NUMBER)
               Sales Item (VBUK-POSNR)              --  (0S_ORD_ITEM)
    Date: Document created date (VBAK-AUDAT) --  0DOC_DATE
    Key field: Netprice (VBAP-NETWR) -- 0NET_VALUE
    3. Delivery Cube (from VCITM)
             Sales order number (VBUK-VBELN)   -- (0DELIV_NUMB)
             Item   (VBUK-POSNR)                         -- (0DELIV_ITEM)
    Date: Delivery Date :LIKP-WADAT_IST      -- 0ACT_GI_DTE
    4. Billing Cube (from VDITM)
              Sales order number (VBUK-VBELN) --  (0BILL_NUM)
              Sales Item (VBUK-POSNR)              --  (0BILL_ITEM)
    Date: Billing Date: (VBRK-FKDAT)             -- (0BILL_DATE)
    Key field: Net price (VBRP-NETWR)       -- 0NETVAL_INV
    I want to combine above cubes. If I combine, Will I get correct data??????
    Points will be assigned to every useful answer

  • How to calculate Last year in BEx Report

    Hi Experts
    I have a requirement to create report in BEx --> report output will be Amount, Diff in percentage(Plan-Actual),Last year
    My question how we calculate the Last year and actual minus plan difference in percentage

    Hi,
    Make use of % functions in query designer to get the desired result.Please search on forum lot of examples will be there.
    Hope it helps.
    Regards,
    AL
    Edited by: AL1112 on Mar 7, 2011 4:56 PM

  • How to get Last Year Sales and YTD Sales without using AGO and TODATE?

    Hi all,
    I have got Company and Time dimensions and Sales Fact. My requirement is to get Last Year sales for each company without using AGO function and YTD without using TODATE function. (Due to performance issue as AGO and TODATE do not insert a Cache entry).
    Can someone please help me to achieve my requirement? Thanks in advance.

    Hi Satya,
    Thanks again for your reply. To start with I don't have data for the years 2012 and 2011 to test as I am using SH sample schema from Oracle. I have applied your solution but it does not seem to be working for the previous years like 2000, 2001. My requirement is to have a dashboard prompt "YEAR" and let the user choose whatever year he wants.
    Please have a look at the column formulas of my analysis (As per your solution) :
    ***here B_YEAR is replaced by CALENDAR_YEAR.  
    Amount: "F1 Sales"."Amount"
    AmountYTD:  FILTER("F1 Sales"."Amount" USING "D1 Time"."CALENDAR_YEAR" =YEAR(CURRENT_DATE))
    Amount LY: FILTER("F1 Sales"."Amount" USING "D1 Time"."CALENDAR_YEAR" =YEAR(CURRENT_DATE)-1)and the physical query generated by BI Server: (as you can see I have got a filter CALENDAR_YEAR= 2000)
    WITH
    SAWITH0 AS (select sum(T1074.AMOUNT_SOLD) as c1,
         sum(case  when T1035.CALENDAR_YEAR = TO_NUMBER(TO_CHAR(TO_DATE('2012-05-03' , 'YYYY-MM-DD'), 'yyyy'), '9999') then T1074.AMOUNT_SOLD end ) as c2,
         sum(case  when TO_NUMBER(TO_CHAR(TO_DATE('2012-05-03' , 'YYYY-MM-DD'), 'yyyy'), '9999') - 1 = T1035.CALENDAR_YEAR then T1074.AMOUNT_SOLD end ) as c3,
         T1035.CALENDAR_MONTH_DESC as c4,
         T1035.CALENDAR_YEAR as c5,
         T1035.CALENDAR_MONTH_ID as c6
    from
         TIMES T1035 /* D1 Time */ ,
         SALES T1074 /* F1 Sales */
    where  ( T1035.CALENDAR_YEAR = 2000 and T1035.TIME_ID = T1074.TIME_ID )
    group by T1035.CALENDAR_MONTH_DESC, T1035.CALENDAR_MONTH_ID, T1035.CALENDAR_YEAR)
    select distinct 0 as c1,
         D1.c4 as c2,
         D1.c5 as c3,
         D1.c1 as c4,
         D1.c2 as c5,
         D1.c3 as c6,
         D1.c6 as c7
    from
         SAWITH0 D1
    order by c3, c2 Thanks in advance.

  • How to get last year records in P&L

    Hii gurus,
    I am creating Profit & Loss report.
    I need to show last year records.
    Please explain.....
    Thanks in advance......
    Moderator message: please do more research before asking, show what you have done yourself when asking.
    Edited by: Thomas Zloch on Sep 27, 2011 2:11 PM

    Hi,
    Better still if you want this to be easily changeable, i.e. not without a repository migration, put the search spec on the Applet in the Application - Personalization screen. In this way you can change the Search Spec in case of Business Requirement change without needing to go through a development cycle. Do not forget to do a Reload Personalization Rules after changing Search Spec to bring this in effect.
    If you have a standard requirement then do it preferably on the Applet so that you can use the BusComp at other locations also without having to deal with the search spec coming in uninvited.
    Thanks and Regards,
    Tanmay Jain.

  • T-SQL how to set last row as first

    Hi,
    I have the following query:
    SELECT leveltmp, 'Level ' + CAST( leveltmp as varchar(5)) + ' (' +
    STUFF((SELECT top(3) ', '+ BES.Name
    FROM BESTB BES
    WHERE BES.leveltmp = BE.leveltmp
    AND BESId=2
    FOR XML PATH('')), 1, 1, '') + ',...)' as 'level'
    FROM BESTB as BE
    WHERE BEId = 2
    GROUP BY leveltmp
    ORDER BY 1
    and I get the following results:
    1    Level 1 ( TestFirstLvl1, TestFirstLvl2, TestFirstLvl3,...)
    2    Level 2 ( TestSecondLvl1, TestSecondLvl2, TestSecondLvl3,...)
    3    Level 3 ( TestThirdLvl1, TestThirdLvl2, TestThirdLvl3,...)
    4    Level 4 ( TestFourthLvl1, TestFourthLvl2, TestFourthLvl3,...)
    5    Level 5 ( TestFifthLvl1,...)
    However, I need the last one always to be the first one, but the others to remain as they are. I need my order to be 5,1,2,3,4 instead of 1,2,3,4,5.
    So basically I need to get the following results:
    1    Level 1 ( TestFifthLvl1,...)
    2    Level 2 ( TestFirstLvl1, TestFirstLvl2, TestFirstLvl3,...)
    3    Level 3 ( TestSecondLvl1, TestSecondLvl2, TestSecondLvl3,...)
    4    Level 4 ( TestThirdLvl1, TestThirdLvl2, TestThirdLvl3,...)
    5    Level 5 ( TestFourthLvl1, TestFourthLvl2, TestFourthLvl3,...)
    Any idea on how to achieve this?
    Thanks

    create table #t (c char(1))
    insert into #t values ('a'),('b'),('c'),('d')
    select * from #t order by c ---now we need d to be first charachter 
    declare @c char(1)=(select top 1 c from #t order by c desc)
    select * from #t order by case when c =@c then '1' else c end
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Select last value for each day from table

    Hi!
    I have a table that stores several measures for each day. I need two queries against this table and I am not quite sure how to write them.
    The table stores these lines (sample data)
    *DateCol1                 Value       Database*
    27.09.2009 12:00:00       100           DB1
    27.09.2009 20:00:00       150           DB1
    27.09.2009 12:00:00       1000          DB2
    27.09.2009 20:00:00       1100          DB2
    28.09.2009 12:00:00       200           DB1
    28.09.2009 20:00:00       220           DB1
    28.09.2009 12:00:00       1500          DB2
    28.09.2009 20:00:00       2000          DB2Explanation of data in the sample table:
    We measure the size of the data files belonging to each database one or more times each day. The value column shows the size of the database files for each database at a given time (European format for date in DateCol1).
    What I need:
    Query 1:
    The query should return the latest measurement for each day and database. Like this:
    *DateCol1       Value      Database*
    27.09.2009        150          DB1
    27.09.2009       1100          DB2
    28.09.2009        220          DB1
    28.09.2009       2000          DB2Query 2:
    The query should return the average measurement for each day and database. Like this:
    *DateCol1       Value      Database*
    27.09.2009       125          DB1
    27.09.2009      1050          DB2
    28.09.2009       210          DB1
    28.09.2009      1750          DB2Could someone please help me to write these two queries?
    Please let me know if you need further information.
    Edited by: user7066552 on Sep 29, 2009 10:17 AM
    Edited by: user7066552 on Sep 29, 2009 10:17 AM

    For first query you can use analytic function and solve it.
    with t
    as
    select to_date('27.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss') dt,       100 val,           'DB1' db from dual union all
    select to_date('27.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       150,           'DB1' from dual union all
    select to_date('27.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1000,          'DB2' from dual union all
    select to_date('27.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1100,          'DB2' from dual union all
    select to_date('28.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       200,           'DB1' from dual union all
    select to_date('28.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       220,           'DB1' from dual union all
    select to_date('28.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1500,          'DB2' from dual union all
    select to_date('28.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       2000,          'DB2' from dual
    select dt, val, db
      from (
    select row_number() over(partition by trunc(dt), db order by dt) rno,
           count(*) over(partition by trunc(dt), db) cnt,
           t.*
      from t)
    where rno = cntFor second you can just group by
    with t
    as
    select to_date('27.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss') dt,       100 val,           'DB1' db from dual union all
    select to_date('27.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       150,           'DB1' from dual union all
    select to_date('27.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1000,          'DB2' from dual union all
    select to_date('27.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1100,          'DB2' from dual union all
    select to_date('28.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       200,           'DB1' from dual union all
    select to_date('28.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       220,           'DB1' from dual union all
    select to_date('28.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1500,          'DB2' from dual union all
    select to_date('28.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       2000,          'DB2' from dual
    select trunc(dt) dt, avg(val) val, db
      from t
    group by trunc(dt), db
    order by trunc(dt)

  • How to select LAST line from a SAP table?

    Hi developers,
    I need to select the last line from a SAP table, NOT from an internal table.
    Something like
    SELECT SINGLE LAST FROM pa00169..
    any help is more than welcome.

    Javier,
    Based on this statement from you:
    "i created a Z table, its a config table that stores some bussines rules, and an id counter, so in order to update that counter i need the last line of the ztable."
    I have one additional solution which is the "text box" approach IF the 'id counter' mentioned above is a numeric data type.
    If so, use an SQL function to get the highest value of ID_COUNTER.
    Then simply add one to it to produce a new, unique, higher-order primary key.
    See below:
    data: l_id_counter like ztable-id_counter.
    data: new_id_counter like ztable-id_counter.
    select max( ID_COUNTER ) from ztable into l_id_counter.
    new_id_counter = l_i_counter + 1.
    Now new_id_counter will be the unique, primary key IF this is the only field in ZTABLE's primary key.
    This will also GUARANTEE that your new record is built correctly.

  • How to select blank as a first element in DropDownBox

    Hi All,
    I have a problem with dropdown boxes. i want to set blank as first value in my dropdown box. SAP has provided with blank but i am using model node. i read about cardinalities and setLeadSelection. but my problem has not been solved. Can any give some suggetions.
    Thanks and Regards
    Ravi Golla

    Hi ,
    Usually , if you make the selection property of the node as 0..1 or 0..n u can achieve it..
    Since its a model node i doubt it.. ! If its a dropdownkey mapped to a simple type.
    a setXXX("  "); would give you an empty value initially... If dropdownbyindex mapped to a model node.. i guess.. you have to copy it to a value node and work on it,
    Regards
    Bharathwaj

  • Are there some audio cd's that i tunes won't accept to burn ? i bought this pc last year and first time i used i tunes and purchased some music and tried to burned it on a cd-r it worked but after that it kept on saying the cd's i am loading were not blan

    is there a setting on how to burn murn from i tunes because it's my first time i tried to burn a cd

    I have an article you can read to burn cd's. but I also have to add that soomtimes you have to play arround with the brand of cd that you use to get the ones that work the best. Hears the link.http://support.apple.com/kb/ht2239

Maybe you are looking for