Need help with select that month range with flexible first date

Hello everyone,
I am trying to create a selection of month range (will be in a WITH clause) for a report to display monthly data. But the first month start date can be any date. (Not necessarily the first date of the month)
Examples:
Report input parameters:
Start Date: 08/10/12
End Month: Dec 2012
I was trying to build a with select that will list
Month_Start, Month_End
08/10/12, 31/10/12
01/11/12, 30/11/12
01/12/12, 31/12/12
OR
Month_Start, Next_Month
08/10/12, 01/11/12
01/11/12, 01/12/12
01/12/12, 01/01/13
End month is optional, so if no value the select will list only
08/10/12, 01/11/12
Oracle Database Details is
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
My code so far is
VARIABLE  P50_START_DATE  VARCHAR2 (10)
VARIABLE  P50_END_MONTH    VARCHAR2 (10)
EXEC  :P50_START_DATE  := '10/10/2012';
EXEC  :P50_END_MONTH   := '31/12/2012';
  SELECT  to_char(:P50_START_DATE) AS start_date
        ,  ADD_MONTHS( TRUNC(to_date(:P50_START_DATE,'DD/MM/YYYY'),'MONTH'), 1) AS next_month
  FROM dual
  union
   SELECT to_char(ADD_MONTHS( TRUNC(to_date(:P50_START_DATE,'DD/MM/YYYY'),'MONTH'), ROWNUM-1)) AS start_date
   ,      ADD_MONTHS( TRUNC(to_date(:P50_START_DATE,'DD/MM/YYYY'),'MONTH'), ROWNUM) AS next_month
   --, rownum
   from all_objects
   where
   rownum <= months_between(to_date(NVL(:P50_END_MONTH, :P50_START_DATE),'DD/MM/YYYY'), add_months(to_date(:P50_START_DATE,'DD/MM/YYYY'), -1))
   and rownum > 1If I put comment – on line and rownum > 1, as
-- and rownum > 1The result I get is
START_DATE                     NEXT_MONTH               
01/10/12                       01/10/12                 
01/11/12                       01/11/12                 
01/12/12                       01/01/13                 
10/10/2012                     01/11/12    But when I try to remove the duplicate period (of the first month) out by restrict rownum, it do not return any rows for the second select at all. The result I get is:
START_DATE                     NEXT_MONTH               
10/10/2012                     01/11/12    Can anyone advise what wrong with the select statement ?
Thanks a lot in advance,
Ann

Hi,
Here's one way:
WITH   params      AS
     SELECT     TO_DATE (:p50_start_date, 'DD/MM/YYYY')     AS start_date
     ,     TO_DATE (:p50_end_month,  'DD/MM/YYYY')     AS end_date
     FROM     dual
SELECT     GREATEST ( start_date
           , ADD_MONTHS ( TRUNC (start_date, 'MONTH')
                        , LEVEL - 1
          )               AS month_start
,     LEAST     ( end_date
          , ADD_MONTHS ( TRUNC (start_date, 'MONTH')
                      , LEVEL
                    ) - 1
          )               AS month_end
FROM    params
CONNECT BY     LEVEL     <= 1 + MONTHS_BETWEEN ( end_date
                                  , TRUNC (start_date, 'MONTH')
;:p50_end_month doesn't have to be the last day of the month; any day will work.
If you want to generate a Counter Table containing the integers 1 througn x in SQL, you could say
SELECT  ROWNUM  AS n
FROM    all_objects
WHERE   ROWNUM  <= x
;but, starting in Oracle 9.1, it's much faster to say
SELECT  LEVEL   AS n
FROM    dual    -- or any table containing exactly 1 row
CONNECT BY  LEVEL <= x
;Also, x can be greater than the number of rows in all_objects.

Similar Messages

  • Need help Connecting Crystal Reports 8.5 with GBS Agency Expert 6.7.6c

    Need help Connecting Crystal Reports 8.5 with GBS Agency Expert 6.7.6c.  I need assistance on connecting these together so I can run a report.  I am not an IT person so if someone could dumb it down it would be great.
    Thanks,
    NBGHealth

    Hello,
    I assume GBS Agency Expert 6.7.6c is some sort of database or data source? If you have an ODBC driver then create or use a System DSN to the database. Then you can create a report using that DSN.
    Otherwise I suggest you contact the makers of GBS Agency Expert 6.7.6c and ask them how to connect to the database.
    Let them know CR is ANSII 92 ODBC 3 compliant.
    Thank you
    Don

  • Looking to replace my Mac Pro 2.1 graphics card with one that is silent with at least 2 DVI outputs (needed for audio production), any recommendations?

    Looking to replace my Mac Pro 2.1 graphics card with one that is silent with at least 2 DVI outputs (needed for audio production), any recommendations?
    Thanks

    Thanks, but are these are silent?
    Why do they cost over 10 x what seems available for PC?
    Is it not possible to flash the cards for mac?
    Something similar to a ASUS Geforce 8400GS PCI-E 2.0 512 MB DDR2 Graphics Card EN8400GS Silent/P/512M?

  • I'm in realestae, and i need a client manager that will sync with my iphone, ipad and mac if i make changes on one device. Any sugestions.

    I'm in realestae, and i need a client manager that will sync with my iphone, ipad and mac if i make changes on one device. Any sugestions.

    Try using icloud and that should solve your problem

  • Need help on selection screen

    Hello Experts,
       I have a requirement. My user want when she run the report online all variable on selection screen should be parameters means not range or extension and some selection screen checks. But when she run the report in batch mode, all variable on the selection screen should be select-options means ranges with extension. Is it possible to create 2 selection screen in same report, I have no idea, is it possible or not. If possible please tell me how.
    Thanks,
    Amit

    Hi,
    Try this code,
      <b>Important thing is, don't use default selection-screen(1000).</b>
    DATA: w_matnr TYPE matnr.
    SELECTION-SCREEN BEGIN OF SCREEN 1001.
    PARAMETER: pr_param  TYPE matnr.
    SELECTION-SCREEN END OF SCREEN 1001.
    SELECTION-SCREEN BEGIN OF SCREEN 1002.
    SELECT-OPTIONS: so_sele FOR w_matnr.
    SELECTION-SCREEN END OF SCREEN 1002.
    INITIALIZATION.
      IF sy-binpt = 'X'.
        CALL SELECTION-SCREEN 1001.
      ELSE.
        CALL SELECTION-SCREEN 1002.
      ENDIF.
    <b>You should be the same logic in the remaining program(like in START-OF-SELECTION, END-OF-SELECTION etc) where ever the implication of selection screen fileds are there.</b>
    Thanks and Regards,
    Bharat Kumar Reddy.V

  • Iphoto will not open I am asked to check with developer that iphoto works with this version of OS x I have followed all the steps recomended and reinstalle ILife but to no avail

    Iphoto will not open I am asked to check with developer that iphoto works with this version of OS x. I have Mountain Lion OS X I have followed all the steps recomended  by T Devlin in a previous discussionand reinstalle ILife but to no avail

    To reinstall iPhoto you'll have to delete the current application and all files with "iPhoto" in the file name with either a .PKG or .BOM extension that reside in the:
    HD/Library/Receipts folder (10.5 and earlier)
    or from the /var/db/receipts/  folder (10.6) .
    or from the /private/var/db/receipts folder (10.7 or later)
    Then install iPhoto from the source it came from originally.

  • My mom and I both have iphone5 but when I send her messages they aren't blue but any other iphone I text is blue I need help to get that fixed

    My mom and I both have iphone5 but when I send her messages they aren't blue but any other iphone I text is blue I need help to get that fixed

    Both of you need to have iMessage activated, and both have to have active Internet connection for iMessage. Are you both using the same Apple ID? Are you using the phone number or Apple ID for messages?

  • Successive dates with  last day of that month being added to succesive date

    Hi ,
    I have a piece of code that displays the succuessive dates from the given date to tilll date with a date interval of 30 days. My requirement goes some thing like this. since the given date is '26-nov-08' the next successive date should be the number of days in nov(30) added to '26-nov-08'. that will be around 26-dec-08. For this date it has to add the number of days in December(31) to '26-dec-08' and that turns out to be '26-jan-09'. and this must go on till date.
    In the below code i have used 30 for the interval of 30 days but the interval has to the last day of the successive date's month( for dec the interval has to 31 and for january the interval has to be 31 and for february 28)
    select to_date('26-nov-08', 'dd-mon-yy') + (level - 1) * 30
    from dual
    connect by level <= trunc((sysdate-to_date('26-nov-08', 'dd-mon-yy'))/30 )Please advice

    hi ,
    the query sent by you is correct and could it be in corporated for this query :
    SELECT TRUNC(inst_due_date) + (LEVEL-1 ) * (ilpa_term_type),iloan_code,LOAN_AMT,FEE_AMT,
    LOAN_DATE,LOAN_STATUS_ID
    FROM (
    SELECT inst_due_date,sm.iloan_code,LOAN_AMT,
    FEE_AMT,
    LOAN_DATE,
    LOAN_STATUS_ID,
    decode(sm.ilp_term_type, 26 ,14,24,15,12,(select to_number(to_char(last_day(inst_due_date),'dd')) from dual)) as ilpa_term_type
    FROM ST_IL_SCHEDULE sc,ST_IL_MASTER sm
    WHERE sc.iloan_code = sm.iloan_code
    AND sc.inst_num = (SELECT MAX(inst_num) FROM ST_IL_SCHEDULE b WHERE b.iloan_code = sc.iloan_code)
    AND sc.iloan_code =123456789)
    CONNECT BY LEVEL <= TRUNC((TRUNC(SYSDATE)-TRUNC(inst_due_date))/(ilpa_term_type) )
    Here we are using the decode concept if ilp_term_type = 26 then 14 but we need to implement the code of adding the number of days to that month in place of this code :
    select to_number(to_char(last_day(inst_due_date),'dd')) from dual:
    Please advice

  • Need help Please. Which play nice with macs? Palm Treo's Or Tmobile MDA?

    Hi all, I post on here from time to time, but hardly anyone ever answers my questions. Here's my dilema. I bought a Tmobile MDA over the weekend that runs microsoft windows mobile 5.0. And while playing with it have noticed some things about it that i think are'nt that good. For example, I like the fact that its a windows os, but think that it's flawed. I have done quite a bit of research but don't think that it's active sync software is even compatible with mac osx. so have'nt even tried to mess with it. now i'm still in the 14 day window and am thinking about returning it. but here's the thing....
    I know that tmobile has EDGE, and it's considerably slower than verizon or sprints EVDO. (since i've researched it i know that edge is around the 70-170KBPS range when EVDO has 300-700KBPS) And tonight i was messing with this tmobile MDA and finally got it to work to connect to the net with it using bluetooth and it's "modem" ability to connect it to the web. But it S U C K S! i went to and did a bandwith test and i was only getting like 12.1-27.1kbps download (after running 2 tests) dude, it feels slower than dialup!
    so with that bullet against it, comes the compatible part. I can't sycn this thing with my mac for NOTHING! do any of you out there have a palm treo? (either verizon, sprint, or att.... carrier X?) How does it sync with your mac? is it hard? any extra software i need to get/buy? have any of you used it to connect to the net? and if so, how's the speed? And here's an even bettter question... How long did it take to config it to work using the phone as a modem? Did you use bluetooth? or serial link? was it easy to config? Where did you find the instructions?
    I know these are a lot of questions, but this is a large investment for me. I mean this thing ain't cheap and it does'nt really play nice. I don't mind paying a little extra, for some peace of mind, and knowing that it won't crash often and will work with my mac. Anyone out there got any other suggestions? I would really appreciate it. I would like your opinion on which one is the easiest to use that plays nice with a mac, and has a interface that's almost as nice. Thank you so much for your time. I will be following this post closely and comment you all back for your replys
    Mac Book Pro 1.83 GHZ 512 Ram   Mac OS X (10.4.5)  

    It really is a toss up cause Ive owned two Treo's and Ive read extensive reviews on Windows mobile devices and it seems to me like they're pretty similar in the way of hardware and software(minus the fact of using different operating systems). So I think the determining factor really ought to be more focused on how much you're willing to pay, and the level of support you get for each device. I recently got rid of my Treo 650 due to an interesting touchscreen problem and got a windows mobile device(should come tomorrow)
    in the way of syncing with a mac:
    The Treo is extremely simple to set up and use with a Mac(keep in mind Im not talking about the 700w/wx)in every aspect. Palm provides OSx compatible software(though its almost impossible to get rid of after installation). However, in my experience, Palm does not really do a good job in the customer service department. While they have a rather extensive support page for each device(some of the info is outdated), that's pretty much all you get unless you don't mind spending hrs scouring various forums. Talking to customer service is a joke. Like I said I had a problem with the touchscreen and the best the rep could give me was "try a hard reset" and "send it in for repair".
    I have yet to experience what windows mobile will be like. At the very least with syncing, theres syncing software made by people who had OSx in mind(ie: Missing Sync or Pocketmac) who will probably be able to help out a lot more in this area and possible also be able to help out with the other issues you mentioned.
    a good place to check out would be howardforums.com, you'll probably get better answers there.

  • I NEED HELP what i have to do with  Palmrest discoloration on my macbook

    I NEED HELP what i have to do or where i have to go to Palmrest discoloration on my macbook.

    well i hope i could but i live in Puerto Rico. theres no apple stores around here. i buy my mac in compu usa here in Puerto Rico i went to the store to show them the problem but they told me that i have to get online and contact apple for a number that the store will use to order the replacement for my laptop but i dont know where i have to go to request this number my macbook have just 3 month with me and it looks really bad!
    Message was edited by: Host

  • I have a godaddy website with a welcome page- I need help adding a few additional pages with a hyperlink to my welcome page.

    I need help attaching a few hyperlinks my godaddy welcome page. I have 2 more ipages articles, I also converted them to pdf. Godaddy only helped (last year) with the 1st article.  I do not know how to attach a hyperlink to the artlcles and add the hyperlinks to my welcome page.

    The program is called Pages not iPages. Just let us know if you do not speak English and what language you do speak so we can adjust for that.
    The issues are to do with your web page not with Pages.
    I think you are asking how to link from your web page to your pdf articles. You must first copy those pdfs to your web server, or some other web location, and then provide html links on your welcome page to those pdf files.
    The pdfs themselves may contain links to other locations but I can not see that that is what you are asking for.
    Nor to what those links would be to.
    From your heading I think you may have confused the name of Pages, the word processing program, with web pages which are two different things.
    Peter

  • Need help connecting to 360 and pc with internet

    im new to using routers and i lost the manual and the box and i need help using the router the model number is NH1005,V2 fast ethernet 10/100 5-port Hub and it is a linksys so can someone help me im confused and i need the ip addreess or something
    thanks in advance

    Hi....
             A network HUB is a network device that is used to connect multiple computer so that they can share the resources. In more general way a hub can be defined as a common connection point for devices in the network.
                There are hubs that can be managed by an administrator. In case of NH1005 it is not a manageable HUB. Connect the devices to the HUB and if the devices are properly configured they will communicate with each other.

  • Need Help! No Video Just Audio With .AVI Files

    i got quicktime for my iPod, just only for that cause i think that quicktime really *****... i searched this whole site for an answer. i found something i thought would solve my problems with .avi files but my .avi files are mpeg-4 layered, and there's only a descent answer for indeo files? or something like that. i really need help cause i want to convert an ordinary .avi file to iPod extension... please please help!!!!!!!!!!!!

    There is no single codec for movies that have .avi extensions. AVI is a container format, not a specific type of file. An AVI movie may use one of the Indeo codecs or one of the various flavors of DivX, among other possibilities. You'll have to find out what codec was used for the movies you want to view to determine what you need. Note that not all codecs for the various .avi movies are available for QuickTime.
    If you want to try "hit and miss", you can try the codecs at http://www.divx.com/ and http://www.3ivx.com/ and see if one of them will work for you

  • Need help on rams to be compatible with my Spec

    Hi I need to replaced my rams. Appreciate some advice here. Currently I am using DDR PC3200/400Mhz rams. As it's no longer economical/ value-for-money for me to get PC3200/400Mhz rams, below are the alternatives I am looking into since their prices are more cost effective than 400Mhz rams. According to my Spec, Intel 2.8Ghz Pentium 4, MSI motherboard 865PE Neo 2 PLS, 478 socket. Will I be able to use PC4200 533Mhz, PC5300 667 DDR2 rams?
    Kingston DDR2 533Mhz 1GB
    Kingston/Corsair DDR2 533 Mhz PC4200 1GB
    Patriot DDR2 PC4200 533Mhz 1GB
    kingston DDR2 PC5300/667Mhz 1GB
    Compatibility and stability is more impt to me. I do not intend to overclocking. Appreciate anyone if you could help advice me on the timing as well for these suggested Rams w/o overclocking.
    Thanks a lot.
    Intel Pentium Prescott 4 CPU 2.8Mhz
    MSI 865PE Neo2 PLS
    1.5GB Ram (2x512MB, 2 X 256MB), 3-3-3-8 clocks at 2.6V
    1 80GB SATA 7200rpm HDD
    1 LG DVD writer
    1 floopy disk
    1 ATI graphic card 9550SE
    PSU +5.5V 24A, +3.3V 15A, 12V1 12A, 12V2 15A

    Quote from: Exo on 21-May-07, 18:23:34
    You can't use DDR2 ram with that board. You need DDR1 PC3200 ram. Best thing to do is sell the ram you currently have and get a new dual channel kit as your slots are already full and further mixing will lead to problems.
    Hi thanks for replying.
    I don't intend to mix the existing rams that I have with a new replace rams. I will just install 2 x 1GB rams. So I need to know if my motherboard will be able to use 1 GB DDR2 533mhz or DDR2 667Mhz rams before I go and buy.
    Really can't use DDR2 rams?

  • Need help in formating a form dealing with negative currency

    Need Help!!!
    Creating forms in Adobe acrobat Pro I could format a number cell to calculate additions/subtractions of currency. If the result was negative I could get the cell to show the negative result in red text and show parentheses around them. How can I do that in LiveCycle?
    If i have to use formcalc - what would i type in?

    In LiveCycle can be done using the Numeric Field object and some formcalc script.
    Use the "Numeric Field" from the Object Library. For the Field patterns (Select the placed numeric field, On object Window Object -> Field) use "num.currency{}" to show the currency(Ex: $) and "parentheses" if its negative. Write some script to show red text/border in red .
    On exit event of the Numeric Field here is the script:
    if($.rawValue <0) then $.font.fill.color.value = "255,0,0" endif  // This will make entire text in red color if the value is negative.
    if($.rawValue <0) then $.validate.nullTest = "error" endif      //This will make border of the field in red color if the value is negative.
    Hope this helps.

Maybe you are looking for

  • Showing more All-Day Events in Month View?

    Even with the iCal window maximized, when more than 4 All-Day events take place on the same day, Month View shows "..." instead of the usual All-Day colour bar, even if there's still half the space left in 'box' for that day.... To be clear: it shows

  • Custom transaction for FBL5N

    HI,   I need to copy the program RFITEMAR to ZRFITEMAR and should create a ZFBL5N. I created a ZRFITEMAR program and created ZFBL5N. When I am executing program standalone it is not giving any dump, but when I am trying to execute newly created trans

  • Operator="in" , Fetch Xml, MS CRM 2011

    hi, i have a guid's string array. ex: string[] recordGuids; i want to use this in fetchxml by using condition operator "in". i have tried this below code but no success ("The remote server returned an error: NotFound."). var fetchXml = @"<fetch mappi

  • Itunes wont download. It always says there is an error

    Why does the itunes download always say there is a error when it is downloading?

  • Session Management in BSP applications

    Hello, I habe been developing the following application to send E-Mails from Outlook to SAP WEB AS Abap Stack: - I have created a COM-Addin in MS Outlook - When the user clicks on a button, that I have created, the currently marked E-Mail-Message is