Need work around to split date range into months

Hi All,
I have a requirement to split the data range in source table to months.
here is the source table
ID Sdate Edate Code
===============================
501 1/4/2009 4/30/2009 AH
501 5/1/2009 9/30/2009 AB
502 1/1/2014 5/31/2014 AC
Here is my target
ID Sdate Edate Code
================================
501 1/4/2009 1/31/2009 AH
501 2/1/2009 2/28/2009 AH
501 3/1/2009 3/31/2009 AH
501 4/1/2009 4/30/2009 AH
501 5/1/2009 5/31/2009 AB
501 6/1/2009 6/30/2009 AB
501 7/1/2009 7/31/2009 AB
501 8/1/2009 8/31/2009 AB
501 9/1/2009 9/30/2009 AB
502 1/1/2014 1/31/2014 AC
502 2/1/2014 2/28/2014 AC
502 3/1/2014 3/31/2014 AC
502 4/1/2014 4/30/2014 AC
502 5/1/2014 5/31/2014 AC
Please provide some input.
Thanks a lot in advance.

That means your database is in a different locale than mine. When I select cast(Edate as varchar), I get the date returned in the format 'YYYY-MM-DD'. That's why I use(left(cast(Edate as varchar),4) + right(left(cast(Edate as varchar),7),2) to get it the format 'YYYYMM' before converting it into an integer.
Your database most probably returns dates in a format like D/MM/YYYY. That's the reason for the error you get. You'll have to select (right(cast(Edate as varchar),4) + left(right(cast(Edate as varchar),7),2) to obtain the same results as I do.
Alternatively, you can use the convert function to obtain the same results:
     select max(
     cast(left(convert(varchar,Edate,102),4) + right(left(convert(varchar,Edate,102),7),2) as int) + 1 -
     cast(left(convert(varchar,Sdate,102),4) + right(left(convert(varchar,Sdate,102),7),2) as int))
     FROM src_split'
It's always good practice to test the SQL-statements in your database client first before including them in a DS script.
Also, I suddenly realise this statement will only return the correct result when your Edate and Sdate are always within the same year. If that's not the case, but the gap between Edate and Sdate is always less than 10 years, change your statement to:
     select max(
     cast(left(convert(varchar,Edate,102),4) + right(left(convert(varchar,Edate,102),7),2) as int) + 1 -
     cast(left(convert(varchar,Sdate,102),4) + right(left(convert(varchar,Sdate,102),7),2) as int)) % 88
     FROM src_split'

Similar Messages

  • CONVERT   DATE RANGE INTO MONTHS

    HI FRIENDS,
    ACTUALLY IN MY SELECT-OPTIONS I HAVE USED DATE BETWEEN 03/06/1980  TO 04/12/1980
    BASED ON THIS DATE I HAVE TO CALCULATE NUMBER OF MONTHS.
    WILL THIS BE DONE AUTOMATICALLY OR I NEED TO WRITE ANY CODE FOR CONVERTING THE DATE RANGE INTO NUMBER OF MONTHS.
    REGARDS
    SIRI.

    Hi,
    Use FM's : MONTHS_BETWEEN_TWO_DATES_NEW
               MONTHS_BETWEEN_TWO_DATES
               FIMA_DAYS_AND_MONTHS_AND_YEARS
    Sample code :
    DATA : x_no_months type i.
    DATA : x_stdat like sy-datum,
           x_enddat like sy-datum.
           x_stdat  = s_date-low
           x_enddat = s_date-high
    CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
        EXPORTING
          i_datum_bis = x_stdat
          i_datum_von = x_enddat
        IMPORTING
          e_monate    = x_no_months.
    x_no_months will contain no.of months.
    Regards
    Appana

  • Split date range without Calendar table

    Hi guys!
    Is there any way to split date ranges (to days / hours / minutes) in one table without using Calendar table (without joining 2 tables)?
    Reason I'm asking this is because we have a huge Fact table (500+ million records) and joining small Calendar table and this huge Fact table takes considerable amount of time.
    So far we tried:
    Join 2 tables (Fact and Calendar)
    Cross Applying Calendar and table-valued function (that returns necessary measures from Fact table)
    and both approaches took few minutes for 1 day to complete.
    Most successful test we had so far was using CLR and executing table-valued functions in parallel for different 15 minute periods. This way we were able to get the results in 3-4 seconds.
    Anyway, is there any effective pure T-SQL way to accomplish this?
    Thanks in advance,
    Miljan

    Try using a temporary table rather than table variable.. You can have a CI on the date column.
    or
    declare @PeriodStart datetime2(0) = '2013-01-05 00:00:00'
    declare @PeriodEnd datetime2(0) = '2013-01-05 02:00:00'
    select T.PeriodStart, T.PeriodEnd, count(Column1)as count1, sum(Column2)as sum1
    from Fact F with(nolock)WHERE F.[Start]>= '19000101' AND <=@PeriodStartand F.[End] >= @PeriodEnd and F.[End] <='20200101'
    group by T.PeriodStart, T.PeriodEnd
    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

  • How to drill date (column )into month in xcelsius

    Hi,
    I am fresher to Xcelsius. I need to know how to drill the date column into month, then further drilling down month to day.
    I have 2 columns
    Date                       Revenue
    1/1/2010                 452553
    2/2/2011                  97992
    3/5/2011                  23526
    4/3/2011                 63563
    If i click " 1/1/2011" date column, i need to see the corresponding month data in seperate chart( i need to get the detailed data).
    I need to know how the datas should be arranged in excel.
    Thanks in Advance
    Regards,
    Abirami

    Hi Abirami,
    To filter out date, you can use calendar component in Xcelsius. This article explains how to use the calendar component in an interactive way.
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/b05b0244-0453-2e10-b4b3-fab707baddaf
    Then with the help of an invisible combo box as explained in the article to could get just the selected month's data in bar chart.
    Hope this helps.
    Regards,
    Anju Saseendran

  • Spliting user entered date range into u201CFrom Date u201C and u201C To dateu201D-user exit

    Hi,
    In the query i have a created a popup variable for date range for which the processing type is customer exit. When the user exceutes the query he gets the popup for the date range with the default values. The default values are set one month backward.
    For example: if today is 5/19/2008, then the popup date range shows 4/19/2008 to 5/19/2008.
    Already there is an user exit written for the same.
    Now the requirement is i need to split From date and to date entered by user and use them in seperate selections to restrict the keyfigure in the keyfigure column of the query.
    Can anyone throw a light on this, how to go about?
    Shall i need to create two different variables from date and two date and populate the values, if yes how can i do that ?
    Thanks,
    Rani.
    Edited by: rani on May 19, 2008 10:22 AM

    Hello Rani,
                     Check this code,
    var1 is already existing variable with values from date and to date values.
    ztest1 is the first customer exit single variable,
    ztest2 is the second customer exit variable.
    ztest1 and ztest2 you can use these variables in the restricted keyfigures which you have mentioned.
    when 'ztest1'.
        if i_step = 2. "after the popup
          loop at i_t_var_range into loc_var_range
          where vnam = 'var1'.
            clear l_s_range.
            l_s_range-low = loc_var_range-low.
            l_s_range-sign = 'I'.
            l_s_range-opt = 'EQ'.
            append l_s_range to e_t_range.
            exit.
          endloop.
        endif.
    when 'ztest2'.
        if i_step = 2. "after the popup
          loop at i_t_var_range into loc_var_range
          where vnam = 'var1'.
            clear l_s_range.
            l_s_range-low = loc_var_range-high.
            l_s_range-sign = 'I'.
            l_s_range-opt = 'EQ'.
            append l_s_range to e_t_range.
            exit.
          endloop.
        endif.
    hope it helps,
    regards,
    karthik

  • Need help for SRM-6 Data Extraction into Bi-7

    Hi Experts,
    I am looking for help regarding SRM DataSource Extraction to BW. I am working on BW project and need to extract data from SRM Data Source 0BBP_TD_CONTR_2 and 0SRM_TD_PRO. I need to know about the extraction process from SRM. Is there a tool available like LO Cockpit in SRM for extraction and how can we manage the delta in it. Or i can use the T-code RSA5 for that and follow the normal process.  If I can get some documentation that can give me an idea for data extraction and delta management  in SRM that would be appreciated. Any kind of help will be welcome.
    Thanks in Advance.

    Hi,
    May help you:----
    How to extract data from SRM into BW system.
    SRM Audit Management Data Extraction into BW
    Procedure for standard data source extraction from SRM to BW 3.5.
    Regards,
    Suman

  • Opendoc date range into Bex query

    We are having an issue when trying to pass a date range in an Opendoc link. The report is built off a BEx query,  within the report we have an Opendoc link into a child version of the report. I can pass all the other prompts with no issue except for one which is the date range.
    I am defining the date range as "[19000101]..[19000101]" but we keep getting this error message:
    Has anyone lese had this issue?
    Thanks

    Hi,
    Try This
    "[Date(2014,04,01)]..[Date(2014,04,11)]"
    "[Date(yyyy,MM,dd)]..[Date(yyyy,MM,dd)]"
    http://help.sap.com/businessobject/product_guides/boexir4/en/xi4_opendocument_en.pdf#page=26
    http://<servername>:<port>/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=Aa6GrrM79cRAmaOSMGoadKI&sID
    Type=CUID&sRefresh=Y&lsRTime+Period:=[2000..2004)
    http://<servername>:<port>/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=Aa6GrrM79cRAmaOSMGoadKI&sID
    Type=CUID&sRefresh=Y&lsRparamStringDR=[h..i]&lsRparamNumberDR=[7..8]&lsRparamCurrencyDR=[3..4]&lsRparamDat
    eDR=[Date(2003,6,7)..Date(2003,6,8)]&lsRparamDateTimeDR=[DateTime(2003,6,1,7,1,1)..Date
    Time(2003,6,1,8,1,1)]&lsRparamTimeDR=[Time(1,1,7)..Time(1,1,8)]&lsRparamUnbound1=(..6)&lsRpara
    mUnbound2=[6..)&lsRparamStringR=[a..d]&lsRparamNumberR=[1..3]&lsRparamCurrencyR=[1..3]&lsRparam

  • How to Calculate Total Worked Hours in a date range

    <p><span>WorkedHours column type is varchar(8) (for HH:MM:SS), <br />how to sum working hours of an employee for every month.</span> <br /></p><p><span>ex. of data : WorkedHours<br /><br />attencode   attendate   WorkedHours<br />1573         20-01-2007    07:34:22<br />1573         21-01-2007    12:31:10<br /><br />how can i sum the WorkedHours and print it in Hours format.<br />(like 20.17 for this 2 values)<br /><br />Can u able to follow me.<br />If not pls. feel free to get more information in this regard.</span></p>

    Create a formula like this :
    ((hour({tmpDate.attendate }) * 60 * 60) +
    (minute({tmpDate.attendate }) * 60) +
    Second({tmpDate.attendate }))/3600
    and then take the Sum of it. You can get the result.
    logic behind this is all the hours and minutes are converted into seconds and then added and divided by 3600 to get the actual hours.
    thanks
    kanak

  • Function Module for separating a date range into days

    Hi all,
    Does anyone know if there is a function module which gives back the list of days when we give a date range as input parameter to the function module. For example, we enter the range 10.07.2006 - 13.07.2006 and the function module gives back a table  in form 10.07.2006, 11.07.2006, 12.07.2006, 13.07.2006.
    Thanks,
    Sükrü

    Hi suekrue,
    1. Exactly for this purpose,
       i have written an
       INDEPENDENT FORM (subroutine)
      wherein we pass
       a) fromdate
       b) todate
       c) ITAB
    2. and it gives all the dates in the internal table.
    3. just copy paste
    4.
    data :  itab type table of sy-datum with header line.
    parameters : fromdate type sy-datum default '20060701'.
    parameters : todate type sy-datum default sy-datum.
    perform getdays tables itab using fromdate todate.
    break-point.
    FORM
    form getdays
    tables itab
    using fromdate todate.
      data : curdate type sy-datum.
      curdate = fromdate.
      do.
        if curdate > todate.
          exit.
        endif.
        itab = curdate.
        append itab.
        curdate =  curdate + 1.
      enddo.
    endform.                    "getdays
    regards,
    amit m.

  • Extracting a count of distinct values between two date ranges over months

    Hi All,
    I am having a bit of difficulty in figuring out the query to build a list of active campaigns over a date range.
    i.e. I have a table with campaign IDs and their start and end date details like this
    Campaign_id     Start_date     End_date
            10001     1-Jun-09     31-May-11
            10002     1-Jun-09     23-Jun-11
            30041     21-Aug-09     31-Dec-09
            20005     3-Jun-10     31-May-11
            90021     21-Nov-09     30-Nov-10
            54000     1-Jun-11     1-Dec-12
            35600     1-Mar-10     31-Mar-12 What the above data means is, for eg. the campaign 10001 is active from 1-Jun-09 to 31-May-11 i.e. for 24 months (inclusive of the month Jun-09 and May-11)
    What I need to figure out is the counts of active campaigns between a date range and display that active count at a month level (for e.g. lets say we want to see all the campaigns that were active
    between the date range '01-JUN-2007' and '30-APR-2012' ). So the partial output would be as seen below. The list would continue till december-2012
    Month    Year    Count of active campaigns
    Jan    2009    0
    Feb    2009    0
    Mar    2009    0
    Apr    2009    0
    May    2009    0
    Jun    2009    2
    Jul    2009    2
    Aug    2009    3
    Sep    2009    3
    Oct    2009    3
    Nov    2009    4
    Dec    2009    4
    Jan    2010    3
    Feb    2010    3
    Mar    2010    4
    Apr    2010    4
    Dec    2012    1 Could anybody please help me with the right query for this.
    Thanks a lot for help
    Regards
    Goldi

    set pagesize 40
    with tab as
                    select 1 id, sysdate -100 start_date, sysdate end_date from dual
                    union
                    select 1 id, sysdate -200 start_date, sysdate -150 end_date from dual
                    union
                    select 1 id, sysdate -600 start_date, sysdate - 400 end_date from dual
                    union
                    select 1 id, sysdate -300 start_date, sysdate - 150 end_date from dual
                    union
                    select 2 id, sysdate -100 start_date, sysdate-50 end_date from dual
          year_tab as
                        select
                                 add_months(min_date, level -1) m
                        from
                                select min(trunc(start_date,'YYYY')) min_date, add_months(max(trunc(end_date,'YYYY')), 12) max_date
                                from tab
                        connect by level <= months_between(max_date, min_date)
    select to_char(m,'YYYY') year_,
             to_char(m,'Month') month_,
             nvl(act, 0) act
    from   year_tab,
                select m date_,count(*)  act
                from tab, year_tab
                where m between trunc(start_date,'MM') and trunc(end_date,'MM')
                group by m
                ) month_tab
    where m = date_(+)
    order by m;
    YEAR_ MONTH_           ACT
    2010  January            0
    2010  February           0
    2010  March              0
    2010  April              0
    2010  May                0
    2010  June               0
    2010  July               0
    2010  August             0
    2010  September          1
    2010  October            1
    2010  November           1
    2010  December           1
    2011  January            1
    2011  February           1
    2011  March              1
    2011  April              0
    2011  May                0
    2011  June               0
    2011  July               1
    2011  August             1
    2011  September          1
    2011  October            2
    2011  November           2
    2011  December           2
    2012  January            2
    2012  February           2
    2012  March              2
    2012  April              1
    2012  May                1
    2012  June               0
    2012  July               0
    2012  August             0
    2012  September          0
    2012  October            0
    2012  November           0
    2012  December           0
    36 rows selected.

  • Reg: Splitting  weekly plan into monthly-Demand planning

    Hi All,
    i need small clarification,
    i have created independent requirement for 3 months and i have splitted into  week format.
    Now i need to see the plan in months in MD63.instead of in week. How to split back into months.( not to cjhange just for display).
    is it possible..?
    Thanks in advance.

    Hi,
      As per my knowledge it is not possible in standard.try to change the lot as following & do the test & give the feedback
    Thanks & Regrards
    Sandeep Kumar Praharaj

  • Crosstab Columns Need to be two different date ranges

    I'm fairly new to CR and don't know crystal or basic syntax or any coding really.
    Using the crosstab expert, I need two columns that are based on a range of dates.  Unfortunately the range of dates are not any of the choices I have when I just bring the date into that column box in the expert.
    My two columns:
    Column 1 = 11/01/2007 12:00:00:00 AM to 10/31/2008 12:00:00:00 AM
    Column 2 = 11/01/2008 12:00:00:00 AM to 10/31/2009 12:00:00:00 AM
    When I insert a crosstab and use the expert I have two choices for the columns box.  I can either create two new formulas or use the group options.  I've tried my very inexperienced hand at creating some formulas with laughable results.  The group options, although lovely, don't meet my very specific date needs.
    Anyone out there have the time to help me?  It would be much appreciated.

    Hello Anne,
    Try creating a formula similar to the following;
    if in datetime(2007,11,1,12,00,00) to datetime(/2008,10,31,12,00,00)
    then "11-2007 to 10-2008"
    else if in datetime(2008,11,1,12,00,00) to datetime(/2009,10,31,12,00,00)
    then "11-2008 to 10-2009"
    and use this formula as the column field in the crosstab.

  • Splitting data up into two columns

    Apologies if this is covered previously ( i'm sure it probably is) i've imported .csv into numbers but the first cell contains two pieces of information separated by a space (TI NUMEROLOGY etc) how do I separate into two cells so I can sort data by the different identifers (TI = Title)
    IB 1859060196
    BI PAPERBACK
    AU SHINE
    BC VXFN
    CO UK
    PD 19990923
    NP 128
    RP 9.99
    RI 9.99
    RE 9.99
    PU CONNECTIONS BOOK PUBLISHING
    YP 1999
    TI NUMEROLOGY
    TI YOUR CHARACTER AND FUTURE REVEALED IN NUMBERS
    EA 9781859060193
    RF R
    SG 2
    GC M01
    DE A unique step-by-step visual approach to numerology
    DE characters and compatibility from names and birth dates.

    Hi Alan,
    Another thought. You can sort the data as it is. Click on Reorganize button on the ToolBar:
    To get:
    Every cell starting with TI and a space will come together, and sorted by whatever follows TI and a space.
    However, if it looks nicer to split the entries, use Badunit's formula.
    Alan wrote: "I also clicked on C2 and went to insert/fill/ but the options are greyed out o I can'r apply to all unless I do it manually... and it's a mahoosive file."
      To fill down, click on C2 then drag the white handle down. Or, select the rows that you want to fill before Insert > Fill (Numbers needs to know how far to fill).
    Ian.

  • Need work around for image gallery with password protected URLs

    Is there a way to display an image gallery that has password protected URLs?
    I can build the image gallery in Siena using an excel table with a list of the images and when I preview the app inside Siena I get the expected credentials prompt from IE, and I enter the credentials and the images load and display with their captions perfectly.
    There are 4-6 images in the gallery.
    When I publish and produce a store app, the app errors out with can’t connect and obviously fails on
        var GenericInitError = "The app could not connect to the server. Please try again later.",
            GenericInitTitle = "Network error";
    Most likely because Siena wants to preload everything and there is no way with preload to enter credentials.
    I am looking for any alternatives that would let me get around this.
    TIA
    -- Barb Bowman

    On Mon, 24 Mar 2014 05:10:01 +0000, Radu Gruian (MSFT) wrote:
    >One possible thing to do would be download and embed the images into your app, eliminating the need for password-based authentication.
    Nope. The app accesses a group of IP Security cameras. Static images would not
    make any sense. And authentication is required. Not negotiable.
    -- Barb Bowman

  • Need help in getting measured data out into excel

    I am trying to get the resistances of multiple thermistors out of the Keithley 2700 .
    When a trigger is given, the data need to be measured and taken out.
    Each and every time i press trigger , the resistance should be measured and taken out.
    All the data obtained should be appended into a single excel file until i press "stop".
    I have been trying to do this for a long time, still have not got the required result.
    Please help me regarding this.
    I am attaching my current VI, do help me by making the necessary changes.
    Please. Its urgent.
    Regards
    Grugh Mike
    Success is Everything !!
    Attachments:
    resistance values.vi ‏47 KB

    Please don't start a new message thread with the same question.
    Continue with your original message thread.

Maybe you are looking for

  • How do I transfer photos from my phone to PC?

    I am having trouble transferring photos from my iphone 4G to my PC.  When I plug in my phone,it's not being recognized on my computer. I obviously don't do this often enough. 

  • SOAP Rx Adapter... 401 Unauthorized.. Content Type: Text/HTML

    Hi, I get 401 unauthorized error while trying to invoke Webservice using Receiver SOAP Adapter.. I know this error is b'cos Content-type = text/html instead of text/xml... So i used the MessageTransform bean with the required parameters... I even dow

  • Ipod Classic - Case Quality ?

    Thinking of replacing my 5th Gen Video Ipod with new 80 GB Classic. How good is the new case ? I have an invisible shield on my current pod for much needed protection. Will I have to shell out more $$ to do the same with the new Classic or have Apple

  • My About:Config settings aren't being saved

    So when I type in the URL bar, it shows, Firefox can't find the file at jar:file:///C:/Program Files/Mozilla Firefox/omni.jar!/chrome/en-US/locale/browser-region/region.properties(search text) so I go to about:config and reset the keyword.url, but ea

  • IDVD will not finalize

    am putting a dvd project together using idvd 7.1.2 on a mac os x running Mountain Lion 10.8.4 My problem is that once I have to project ready to burn it goes through encoding process fine but when it gets to the final burn stage it starts the "writin