Amount of days in each month

Post Author: mike7510uk
CA Forum: Formula
i have a report where i have the days of the month along the top. I use this formula to get the day number
... int(day(DateAdd ("D",0,cdate({Command_1.startdate} )))) ...
where the 0 is incremented along the report up to 30. The startdate bit of the formula is a pre-defined date such as 01-04-2007 (1st april)
The fields then all work up to the point of 30th, i need it to end there and not go into the next month (1st)
Obviously this is fine if the month has 31 days as it will just display 1-31. I need some IF statements maybe that looks at which month is selected and displays the correct amount of days.
Any ideas?

Post Author: SKodidine
CA Forum: Formula
The easiest way to get the last day of the month (and hence the number of days in a month) is to use the custom function that comes with CR.  I have only worked with CR XI so not sure about other versions.
1. Open the formula workshop.
2. From the Repository Custom Functions, under Crystal and then Date, RIGHT click on cdlastdayofmonth, click on ADD TO REPORT.
3. Create a new formula, in the formula workshop, under FUNCTIONS, go down the list till you see "CUSTOM FUNCTIONS", expand that till you see cdlastdayofmonth.
4.  In your formula, type cdlastdayofmonth(currentdate)
5. Save and close and display the formula in your report, you should see 04/26/2007, depending on your date format.
You can customize the formula to suit your needs, and this way you do not have to worry about leap years..

Similar Messages

  • How can I set an event to repeat on a week day rather than a numerical day of each month?

    How can I set an event to repeat on a week day rather than a numerical day of each month? I see an option at the bottom of the repeat window .... but I cannot use it. Actually, when I try it freezes up my Calendar.
    Lorrene Baum Davis

    These scrrenshots are from Snow Leopard - I would think that Lion wouldn't be too much different.

  • Amount of days in a month

    Hi. How do I retrieve the amount of days in a month? Thanks.

    here is a long way....
    if the  month is January return 31
    if the  month is Feburay return 28 or was this year a leap year.......
    if the  month is March return 31
    ........ and so one..
    //but there is a better way just figure it out!!!!!David

  • Define event to repeat on the last day of each month?

    (I've searched the forum and can't find this question addressed)
    I want to create a repeating event for the last day of each month. Is this possible?

    Unfortunately Apple does not have an option available that allows you to add an event repeating on the last day of the month. An "OK" way around this would be to repeat on the 1st of every month and send a reminder a day earlier. I know this is less then perfect but the only option currently available. If you happen to find a 3rd party program that allows such integration please don't hesitate to mention it here as I have been looking for this sort of option for quite some time now!

  • Creating new report 1st day of each month

    Hello, all!
    I have a vi that I run to record pressure on test units.  I want to create a new excel report on the 1st day of each month.  If it is not the 1st day of the month I want to just add the data for each test unit as a new worksheet.  I have looked around and can't find a post for what I need to do exactly.  If anyone can help, greatly appreciate.

    Hey END82,
    I agree with RTSLVU's suggestion of using the Seconds to Date/Time vi. From there you can wire the day of the month into a case structure, and have the case for day number 1 to be where you create a new excel report and have the other default case add the data to the report. 
    I attached a VI Snippet which you can drag onto a block diagram to look at.
    Hope this helps!
    Joe S
    Applications Engineer
    National Instruments
    Attachments:
    date.png ‏13 KB

  • Check if a license exists for at least one day in each month

    How to check if a license exists for at least one day in each month for a given period ? Example : If we have a review period from Jan 25 2009 to Aug 15 2009. How to check if there is license for at lease one day in every month.

    Hi,
    Welcome to the forum!
    (1) construct a table or result set that has one row per month in the review period. [This thread|http://forums.oracle.com/forums/thread.jspa?messageID=3651350?] has a similar problem.
    (2) outer-join your actual data to that result set
    (3) use the aggreagate COUNT (x) function (where x is some column from your table) to see if there were any matches in each month. GROUP BY months.
    For a more specific answser, ask a more specific question.
    Post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data.
    It never hurts to say what version of Oracle you're using.
    Edited by: Frank Kulash on Jul 28, 2009 1:54 PM
    Maybe something like:
    WITH  all_months  AS
         SELECT     ADD_MONTHS ( TRUNC ( &period_begin_date
                                , 'MM'
                      , LEVEL - 1
                      )         AS month_date
         FROM    dual
         CONNECT BY  LEVEL <= 1 + CEIL ( MONTHS_BETWEEN ( &period_end_date
                                                          , &period_begin_date
    SELECT       m.month_date
    ,       CASE  COUNT (l.license_date)
                WHEN  0  THEN  'Nothing this month'
                          ELSE  'Some licenses issued'
           END     AS summary_txt
    FROM            all_months     m
    LEFT OUTER JOIN     license_table     l     ON  m.month_date     = TRUNC (l.license_date, 'MM')
                                     AND l.license_date     BETWEEN  &period_begin_date
                                                AND      &period_end_date
    GROUP BY  m.month_date
    ORDER BY  m.month_date
    ;Untested

  • How do I find the start day of each month

    Hi all,
    Hope someone can give a a hand here I've to do a calender project for college and I'm not allowed to use any built in Java classes so fun all the way so far :-)
    I've got one question that is bugging me at the moment. and that is how to find the start day for each month in a year and store them in an array.
    I'm starting my week at Monday (0) and stopping at Sunday (6) and I do have a formula for discovering the first day in Jan of the given year its
    ((y-1900)*365 + (y-1901)/4)%7
    I was just wondering how I could amend this to find the first day in Feb, March etc.
    Any suggestions greatly accepted.
    Thanks in advance.

    Irish-Student wrote:
    newark maybe I didnt make clear exactly what I want to do.
    I have each day of the week starting at 0 for Monday up to 6 for Sunday I want to map what the start day of a month as a number between 0 and 6.
    The formula I have discovering the first day of Jan of a given year will give you 1 i.e. Tuesday
    what I need to do is find out what number between 0 and 6 the start day of each other month of a given year is.
    For example the 1st of Feb is a Friday which is 4 on the weekday map.
    Your suggestion of 31%7 won't work for this, sorry more than likely my fault for not being clearer in what my requirements were.
    Cheers for the help so far and yep your right not being able to use the built in classes is a pain :-)
    Edited by: Irish-Student on 03-Mar-2008 20:01This doesn't really change much of my first suggestion. If you can already calculate the first day of the month of January for any given year, then there's no problem figuring out the other months. Say I want to know the first day April 1, 1978. You already know how to find January 1, 1978. So find that. Then find the number of days between January 1 and April 1 (remember to account for leap years). Once you have the number of days, you can figure out how many weeks and days that is, and thus what day of the week it is.

  • Last day of each month in a year based on a Input date?

    Hi all,
    I have a request from a customer who wants to have a yearly report created in BEx Query Designer which starts in January up to December and they want to have a Month To Date (MDT) and Year to Date (YTD) calculation of a key figure. This report will only show one year at the time based on the date the user give as input at the Variable Screen.
    This key figure should be calculated by using the last date of each month for input when performing the MTD and YTD calculation and summarizations.
    Example:
    January: 31.01.2008  Key Figure = 1000. MTD = 1000 and YTD = 1000
    February: 29.02.2008  Key Figure = 2500. MTD = (2500-1000) 1500 and YTD = 2500
    March: 31.03.2008  Key Figure = 6000. MTD =(6000-2500)=3500 and YTD = 6000
    Etcu2026.
    This means that I have to have a lot of hidden Key figures which gets restricted on the different month end dates and formulas to calculate the different MTD and YTD results for the months as the year progresses.
    The way I have solved it now is that I have a Customer Exit which gives me the Last day of last year (Exp: 31.12.2007) based on input date and use a Offset on the last day of last year date to get the different last dates of each month.
    Since we have a leap year (one extra day in February) this year, the offset to calculate the end month dates will be different for 2007 and next year (2009). This solution is not very flexible, and it will not give the correct MTD and YTD if the customer wants to go back to 2007 and off course next year (2009).
    One solution is to create 12 Customer Exits that gives me the different month end dates (January-December), and also takes in account leap year for February for the different years. These Exits will be based on the Input date the Customers put in at the variable screen.
    I would rather want to avoid making 12 new customer exits and want your advice and expertise to find out if this is possible in any other way (maybe with only 1 customer exit) to get the last date of each month based on an input date.
    Thanks for all your advices on beforehand.
    Regards
    Oddmar Lid

    Hi,
    Thanks for you replay and documentation, but it doesn't give me excatly the functionality I'm after. The only MTD calculation code the document provides is the calculation of the following functionality:
    "Month to Date (MTD) u2013 From the 1st of month to u201CKey Dateu201D - for current year." This doesn't give the the functionality I want, which is to retrieve a given vaule for a Key Figure for the last dates of the months in a year to calculate MTD and YTD.
    This way I have created the query is to have multiple hidden Key Figures that calculates the MTD and YTD.
    In Columns in Query Designer it will look something like this:
    Selection: MTD January--> Date = 31.01.2008, Key Figure (Always Show)
    Selection: YTD January --> Date= 31.01.2008, Key Figure (Always Show)
    Selection: MTD February --> Date= 29.02.2008, Key Figure (Always Hide)
    Formula: MTD February --> MTD February - MTD January (Always Show)
    Selection YTD February --> Date = 29.02.2008, Key Figure (Always Show)
    And so on....
    This is off course a simplified version, but it shows the core of the solution. What I want to achive here is that the dates used to get the Key Figures (last date of a month) is calculated as flexible as possible, so that the users can go back and forth in time without worrying about the leap year problem and so on. I have now used an offset from the last date of last year and this is good for all the normal years, but when it is a leap year the query will use wrong dates to get the key figure vaule for the last date of each month.
    Any ideas on how to achieve this without creating 12 different Customer Exit variables (one for each end date of each month)?
    Thanks
    Regards
    Oddmar Lid

  • Scheduling an Event to Repeat on the i'th week day of each month

    Regular repeating, meetings generally fall on the something like the "second Tuesday of each month". This type if option is available on both my Palm devices and Google calendars. Is there a way to do this on the IPhone? It seems like a pretty basic scheduling option to be missing. Does Apple keep a list of enhancement requests and their status?

    I know this may not be the way we all want it to work, but if you make your custom repeat on your computer and then sync to the phone, it will work fine. That is, if you make an event in outlook (I'm on a mac so I use iCal, but I'm pretty sure it works the same) and set the repeat to the 2nd Tuesday of each month, when you sync and then look at the event on your iphone, you'll see the repeat is set to "custom", and when you tap the edit button, you'll see that it says "second Tuesday of each month".
    I agree this functionality should be in the iphone itself, as it can recognize the repeats, but at least at this point they can't be edited on the iphone itself but for the simple set of choices there.

  • How to create appointment occurs last day of each month

    Hi Preston,
    I am trying to create a monthly recurring appointment occurs on last day of every month in .Net. E.g. start at May 31, 2010 end at May 31 2011 every month.
    I specified the frequency as monthly, byMonthDay[0] = (sbyte)31. But this only generates the instances on those months contain the 31th day. My question is how to also create instances on 30th day for those months don't contain the 31th day.
    Thanks,
    John

    The recurrence rule logic is patterned after the recurrence
    logic in iCalendar (http://www.ietf.org/rfc/rfc2445.txt)
    If you have questions, first look there. Then look at the
    schema itself.
    In the schema the definition of DayOfMonth will handle
    negative numbers:
    <xs:simpleType name="DayOfMonth">
    <xs:restriction base="xs:byte">
    <xs:minInclusive value="-31"/>
    <xs:maxInclusive value="31"/>
    </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="DayOfMonthList">
    <xs:sequence>
    <xs:element name="day" type="tns:DayOfMonth" minOccurs="0"
    maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    So, the last day of the month would be -1. The second
    to last day would be -2 and so on.
    >>> On Wednesday, May 26, 2010 at 11:56 AM, Johnny
    77<[email protected]> wrote:
    > Hi Preston,
    >
    > I am trying to create a monthly recurring appointment occurs on last
    > day of every month in .Net. E.g. start at May 31, 2010 end at May 31
    > 2011 every month.
    >
    > I specified the frequency as monthly, byMonthDay[0] = (sbyte)31. But
    > this only generates the instances on those months contain the 31th day.
    > My question is how to also create instances on 30th day for those months
    > don't contain the 31th day.
    >
    > Thanks,
    > John

  • SQL to display start, end date, days in each month between 2 dates

    HI all,
    Please hep since I'm so new on this. I have a date range 01/15/2012 to 11/26/2012. What I have to do is to display it like below:
    01/15/2012, 01/31/2012, 16 days
    02/01/2012, 02/29/2012, 29 days
    03/01/2012, 03/31/2012, 31 days
    11/01/2012, 11/26/2012, 26 days.
    Thanks for helping me.

    Hi Harvey,
    Try this....
    SELECT TO_DATE ('15-JAN-2012') start_date,
           LAST_DAY ((TO_DATE ('15-JAN-2012')))
                 end_date,
           (LAST_DAY ((TO_DATE ('15-JAN-2012'))) - TO_DATE ('15-JAN-2012')) no_of_days
      FROM DUAL
    UNION
    SELECT start_date, end_date, no_of_days
      FROM (SELECT     (TO_DATE ('15-JAN-2012') + LEVEL) start_date,
                       LAST_DAY ((TO_DATE ('15-JAN-2012')) + LEVEL)
                             end_date,
                       (  LAST_DAY ((TO_DATE ('15-JAN-2012')) + LEVEL)
                        + 1
                        - (TO_DATE ('15-JAN-2012') + LEVEL)
                       ) no_of_days
                  FROM DUAL
            CONNECT BY LEVEL <= (TO_DATE ('26-NOV-2012') - TO_DATE ('15-JAN-2012')))
    WHERE (   TO_CHAR (start_date, 'DD') = '01'
            OR start_date = TO_DATE ('15-JAN-2012')
            OR start_date = TO_DATE ('26-NOV-2012')
       AND start_date < TRUNC (TO_DATE ('26-NOV-2012'), 'MON')
    UNION
    SELECT TRUNC (TO_DATE ('26-NOV-2012'), 'MON') start_date,
           TO_DATE ('26-NOV-2012')
                 end_date,
           (TO_DATE ('26-NOV-2012') + 1 - TRUNC (TO_DATE ('26-NOV-2012'), 'MON')) no_of_days
      FROM DUAL;
    I Have hot coded the dates.. You can use parameters as start date and date
    Hope it will work.
    Regards,
    Soofi

  • TS3999 Why can I only access my Apple ICloud Calendar (on the computer) during the last 6-7 days of each month ??

    I never alter any of the IPhone settings nor any of the computers settings - yet every month it only works from about the 25th and stops again on the 1st.  Anyone any ideas or solutions ??

    Anyone ?

  • When I try to synchronise my calendar it all goes wrong when I have recurring appointments which I enter on Outlook. These are in the format ' first Tuesday of each month' as I play Bridge with different partners on different days each month so it is NOT

    When I try to synchronise my calendar it all goes wrong when I have recurring appointments which I enter on Outlook. These are in the format ' first Tuesday of each month' as I play Bridge with different partners on different days each month so it is NOT every 4 weeks necessarily, it depends on the month.  These get lost on synchronisation or sometimes end up on a totally different day/date.  What can I do as it is very annoying.
    Also it altered some theatre dates where I had entered both date and name of play - the name of the play vanished when I synchronised not just on i-pad but it deleted the info from Outlook as well.

    Others have the same complaint.  iCal on the iPad can do recurring appointments, but not in the format you want (First Tuesday of every Month).  It will do the same DATE each month (e.g, the 25th of each month), but for now it does not do a particular DAY of each month.

  • ABAP for the first day of the month

    Hello BW users,
    I have a scenario which uses an ODS with cumulative key figures with Addition update type. An infocube gets data from ODS by start routine in cube's update rule. I update this ODS first then infocube. All the loads are Full and are loaded daily. This is a snapshot scenario and I load the ods on itself then load from another infocube let's say Cube1. After successful load, I update infocube on itself again then update from the same infocube, Cube1, as in ODS. Infocube load sequence is same as ODS. In the scenario ODS and infocube are wanted to be updated daily. Therefore, I have to delete the ODS's (since it is addition update type) and infocube's overlapping data in the process chain that automates the load. At this point I need two things:
    1- ABAP program that is going to give me the first day of each month.
    2- ABAP program that is going to delete the overlapping data in ODS when I load it daily. Since I can do that for infocube in process chain with standard process type of Delete overlapping requests from infocube I need it only for ODS. Because there is no standard process type to delete overlapping requests in ODS (since its update type is Addition).
    I appreciate your help. Thank you in advance.
    Sincerely,

    1- ABAP program that is going to give me the first day of each month.
    if sy-datun+6(2) = 01.
    SY-FDAYW should give you the day
    endif.
    2- ABAP program that is going to delete the overlapping data in ODS
    REPORT  <PGM NAME>.
    TABLES: RSODSACTREQ , rsseldone.
    Parameters : odsname type RSINFOCUBE default '<>ODS NAME'.
    DATA: temp_REQUEST LIKE RSODSACTREQ-REQUEST,
          temp_REQUEST1 LIKE RSODSACTREQ-REQUEST,
          temp_RNR LIKE rsseldone-RNR.
    DATA: BEGIN OF itab OCCURS 0,
          REQUEST LIKE RSODSACTREQ-REQUEST,
          TIMESTAMP LIKE RSODSACTREQ-TIMESTAMP,
          END OF itab.
    DATA: BEGIN OF itab1 OCCURS 0,
          RNR LIKE rsseldone-RNR,
          seldate LIKE rsseldone-seldate,
          seltime LIKE rsseldone-seltime,
          END OF itab1.
    SELECT REQUEST TIMESTAMP FROM RSODSACTREQ INTO TABLE itab
      WHERE ODSOBJECT = '<ODS NAME>'.
    SORT itab DESCENDING BY TIMESTAMP .
    READ TABLE itab INDEX 1.
    temp_REQUEST = itab-REQUEST.
    SELECT RNR seldate seltime FROM rsseldone INTO TABLE itab1
      WHERE source = '<Info Source Name for the ODS>'.
      SORT itab1 DESCENDING BY seldate seltime .
      READ TABLE itab1 INDEX 1.
      temp_RNR = itab1-RNR.
    *If   temp_REQUEST = temp_RNR .
    CALL FUNCTION 'RSSM_PROCESS_REQUDEL_ODSO'
      EXPORTING
        I_ODS             = odsname
        I_REQUEST         = temp_REQUEST
        I_JOBNAME         = 'i_jobname'
        I_VARIANT         =
        I_INSTANCE        =
      IMPORTING
        E_ERROR           =
        E_T_MSG           = itab1
      E_T_RNRLIST       =    ITAB1.
    *else.
    *raise exception.
    *endif.
    clear itab.
    refresh itab.
    SELECT REQUEST TIMESTAMP FROM RSODSACTREQ INTO TABLE itab
      WHERE ODSOBJECT = '<ODS NAME>'.
    SORT itab DESCENDING BY TIMESTAMP.
    READ TABLE itab INDEX 1.
    temp_REQUEST1 = itab-REQUEST.
    if temp_REQUEST = temp_REQUEST1.
    raise exception .
    endif.

  • Count days in a month for a date range

    i am trying to find no. of days between 2 Date Ranges for a list of Ids. i used the logic in the below link:
    count days of the month
    My query is giving duplicates since, I have list of Ids.
    Doctor_ID     Patient_ID     ARRIVE_DT_TM     DISCH_DT_TM
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45
    763305     42972232     1/7/2013 20:27     3/15/2013 19:15
    25391509     42972298     2/4/2013 22:45     3/8/2013 22:03
    746779     42972331     1/4/2013 23:00     3/26/2013 21:50
    763305     42972338     3/4/2013 22:19     3/6/2013 19:35
    763305     42972411     11/4/2013 22:32     3/29/2013 17:30
    I am looking for query to give me for Patient_ID = 42972229
    MONTH     COUNT_DAYS
    201210     14
    201211     30
    201212     31
    201301     31
    201302     28
    201303     14
    I am running the following code and it loops through the months and gives duplicates when I remove where Patient_id IN (42972229)
    select
    Doctor_ID
    , Patient_ID
    , AR_DTTM
    , DSC_DTTM
    , TO_CHAR(ADD_MONTHS(TRUNC(date1, 'MONTH'), LEVEL - 1), 'YYYY MM') MONTHS_BET
    , (LEAST(date2, ADD_MONTHS(TRUNC(date1, 'MONTH') - 1, LEVEL)) - GREATEST(date1, ADD_MONTHS(TRUNC(date1, 'MONTH'), LEVEL - 1)))+ 1 AS DAYSCOUNT
    from (select
    Doctor_ID
    , Patient_ID
    , ARRIVE_DT_TM AR_DTTM
    , DISCH_DT_TM DSC_DTTM
    ,TRUNC(ARRIVE_DT_TM,'DDD') AS date1
    ,TRUNC(DISCH_DT_TM,'DDD') AS date2
    from temp where Patient_id IN (42972229)
    CONNECT BY LEVEL <= MONTHS_BETWEEN(TRUNC(date2, 'MONTH'), TRUNC(date1, 'MONTH')) + 1
    Please help!

    Hi,
    ASTRA_007 wrote:
    Results I would like to see are:
    Doctor_ID     Patient_ID     ARRIVE_DT_TM     DISCH_DT_TM     Month     CountofDays
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45     2012 10     14
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45     2012 11     30
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45     2012 12     31
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45     2013 01     31
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45     2013 02     28
    755722     42972229     10/18/2012 7:50     3/14/2013 20:45     2013 03     14
    763305     42972232     1/7/2013 20:27     3/15/2013 19:15     2013 01     25
    763305     42972232     1/7/2013 20:27     3/15/2013 19:15     2013 02     28
    763305     42972232     1/7/2013 20:27     3/15/2013 19:15     2013 03     15
    and so on...So each row represents a patient-month, and you want to display several columns from the temp table on each output row. In that case, include all those columns in both the SELECT and GROUP BY clauses, like this:
    WITH     universe     AS
         SELECT     *
         FROM     temp
    --     WHERE     patient_id     IN (42972229)
    ,     date_range     AS
         SELECT     TRUNC (MIN (arrive_dt_tm))     AS first_date
         ,     TRUNC (MAX (disch_dt_tm))     AS last_date
         FROM     universe
    ,     all_dates     AS
         SELECT     first_date + LEVEL - 1     AS a_date
         FROM     date_range
         CONNECT BY     LEVEL     <= (last_date + 1) - first_date
    SELECT    u.doctor_id
    ,       u.patient_id
    ,       u.arrive_dt_tm
    ,       u.disch_dt_tm
    ,       TO_CHAR ( TRUNC (a.a_date, 'MONTH')
                  , 'YYYY MM'
                )          AS month
    ,       COUNT (*)          AS count_days
    FROM       all_dates  a
    JOIN       universe   u  ON  a.a_date  BETWEEN  TRUNC (u.arrive_dt_tm)
                                         AND      u.disch_dt_tm
    GROUP BY  u.doctor_id
    ,       u.patient_id
    ,       u.arrive_dt_tm
    ,       u.disch_dt_tm
    ,         TRUNC (a.a_date, 'MONTH')
    ORDER BY  u.patient_id
    ,       TRUNC (a.a_date, 'MONTH')
    ;Output from your sample data (with no filtering):
    `DOCTOR_ID PATIENT_ID ARRIVE_DT_TM     DISCH_DT_TM      MONTH   COUNT_DAYS
        755722   42972229 10/18/2012 7:50  3/14/2013 20:45  2012 10         14
        755722   42972229 10/18/2012 7:50  3/14/2013 20:45  2012 11         30
        755722   42972229 10/18/2012 7:50  3/14/2013 20:45  2012 12         31
        755722   42972229 10/18/2012 7:50  3/14/2013 20:45  2013 01         31
        755722   42972229 10/18/2012 7:50  3/14/2013 20:45  2013 02         28
        755722   42972229 10/18/2012 7:50  3/14/2013 20:45  2013 03         14
        763305   42972232 1/7/2013 20:27   3/15/2013 19:15  2013 01         25
        763305   42972232 1/7/2013 20:27   3/15/2013 19:15  2013 02         28
        763305   42972232 1/7/2013 20:27   3/15/2013 19:15  2013 03         15
      25391509   42972298 2/4/2013 22:45   3/8/2013 22:3    2013 02         25
      25391509   42972298 2/4/2013 22:45   3/8/2013 22:3    2013 03          8
        746779   42972331 1/4/2013 23:0    3/26/2013 21:50  2013 01         28
        746779   42972331 1/4/2013 23:0    3/26/2013 21:50  2013 02         28
        746779   42972331 1/4/2013 23:0    3/26/2013 21:50  2013 03         26
        763305   42972338 3/4/2013 22:19   3/6/2013 19:35   2013 03          3
    In the end the objective is to count the no. of days in each month between the arrival and discharge dates by Physician and for his/her patients.Then is the output above really what you want? Say you're interested in physician 763305. That physician had 18-patient days in March, 2013, but the output doesn't make it clear.
    I ran your query, it works great but I have a long list of patients for whom I have to run these counts.the query above includes all patient_ids.
    That's a separate problem, to be solved in the first sub-query, universe. The rest of the query will be unchanged.
    How will you know which patients to include? If you can derive the list from temp itself, just use a WHERE clause in universe. If you need to look at other tables, join them in universe, or use them in sub-queries in universe, or both.
    For exmple, if you decide that the list of patient_ids has no pattern, and that you'll need to store their ids in a separate table (perhaps a global temporary table), then universe might be:
    WITH     universe     AS
         SELECT     t.*     -- or list columns needed
         FROM     temp                        t
         JOIN     patient_ids_to_include  p 
                      ON  p.patient_id = t.patient_id
    ) ...The rest of the query can be the same as above.
    If a same patient is admitted again then Patient_ID will be different no matter when readmitted.Are you saying that patient_id identifies a visit, not a patient, and that the same person is assigned a different patient_id every time that person is admitted?
    For
    INSERT INTO temp (doctor_id, patient_id, arrive_dt_tm, disch_dt_tm)
    VALUES ( 755722
    , 42972229
    , TO_DATE ('03/14/2013 23:00', 'MM/DD/YYYY HH24:MI')
    , TO_DATE ('04/01/2013 12:00', 'MM/DD/YYYY HH24:MI')
    First the Patient ID will be different from the earlier admission. Second the results will show like:
    Doctor_ID     Patient_ID     ARRIVE_DT_TM     DISCH_DT_TM     Month     CountofDays
    755722     42972229     3/14/2013 23:00     4/1/2013 12:00     2012 03     14
    755722     42972229     3/14/2013 23:00     4/1/2013 12:00     2012 04     1Are you saying that temp.patient_id is unique, and so the situation is impossible?
    Edited by: Frank Kulash on May 7, 2013 10:23 AM

Maybe you are looking for

  • Error while joining server to Srv Pool. Visible only on 1 server out of 9

    Hello, I am hiaving issues with joining a server to the server pool I have checked the 02cb ond ocfs2 config and they seem to be fine and in line with the other VM servers which are already added to the pool... I have checked the DMESG and ovs-operat

  • Need Acrobat 9 standard.

    I need Adobe Acrobat 9 Standard (only pro is available for download). Have multiple license numbers, just need the install.

  • DAC Execution plan build error - for multi-sources

    We are implementing BI apps 7.9.6.1 Financial& HR analytics. We have multiple sources ( Peoplesoft (oracle)8.9 & 9.0, DB2, Flat file ....) and built 4 containers one for each source.We can build the execution plan sucessfully, however getting the bel

  • I can't get icloud to sync ALL of my information, only my calendar!?

    I have opened an account and am successfully using the iCloud calendar which automatically updates between my Mac and iPhone 4, as expected. However, it took a while for this to work and I still can't get any of the other applications, like Reminders

  • Loading fails, when classes from other packages are referenced

    My applet follows a simple package structure. There's package P1 and there's another package in it P2 (P1.P2) P1 contains Applet class A. P2 contains another class C and interface I. C implements I. A contains a reference of C, which is initialized i