Need working days for all months in a given year

Hi,
I need no of working days for all the months in a given year.
(i.e year is the input and the query should return 12 columns(jan-dec). Saturday and Sunday are holidays)
Regards,
Vignesh

Maybe you can use this:
break on month skip 1
set linesize 200
set pagesize 2000
column month format a20
column week format a4
with req as (select '&Required_Year_YYYY' as yr from dual)
    ,offset as (select case when to_char(trunc(to_date(yr,'YYYY'),'YYYY'),'IW') in ('52','53') then 1 else 0 end as offset from req)
select lpad( Month, 20-(20-length(month))/2 ) month,
       '('||week||')' as week, "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"
from (
  select to_char(dt,'fmMonth YYYY') month,
  case when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 0 then '53'
       when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 1 then '54'
       when to_char(dt, 'mm') = '01' and to_char(dt,'iw') in ('52','53') then '1'
       else to_char(to_number(to_char(dt,'iw'))+offset) end as week,
  max(decode(to_char(dt,'d'),'1',lpad(to_char(dt,'fmdd'),2))) "Su",
  max(decode(to_char(dt,'d'),'2',lpad(to_char(dt,'fmdd'),2))) "Mo",
  max(decode(to_char(dt,'d'),'3',lpad(to_char(dt,'fmdd'),2))) "Tu",
  max(decode(to_char(dt,'d'),'4',lpad(to_char(dt,'fmdd'),2))) "We",
  max(decode(to_char(dt,'d'),'5',lpad(to_char(dt,'fmdd'),2))) "Th",
  max(decode(to_char(dt,'d'),'6',lpad(to_char(dt,'fmdd'),2))) "Fr",
  max(decode(to_char(dt,'d'),'7',lpad(to_char(dt,'fmdd'),2))) "Sa"
  from ( select trunc(to_date(req.yr,'YYYY'),'y')-1+rownum dt
         from all_objects, req
         where rownum <= add_months(trunc(to_date(req.yr,'YYYY'),'y'),12) - trunc(to_date(req.yr,'YYYY'),'y') )
      ,offset
  group by to_char(dt,'fmMonth YYYY'),     case when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 0 then '53'
                                                when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 1 then '54'
                                                when to_char(dt, 'mm') = '01' and to_char(dt,'iw') in ('52','53') then '1'
                                                else to_char(to_number(to_char(dt,'iw'))+offset) end
  ) x
order by to_date( month, 'Month YYYY' ), to_number(x.week)
/ L.

Similar Messages

  • Need working days for a particular month and year

    Hi,
    I need the number of working days for a particular month and year.Saturdays and Sundays are holidays.
    Regards,
    Vignesh

    Try this:
    SQL> var yr NUMBER;
    SQL> exec :yr := 2010;
    PL/SQL procedure successfully completed.
    SQL> with t as (select :yr yr from dual)
      2  SELECT TO_CHAR(dat,'MON-RR'),COUNT(*) FROM
      3  (select TO_DATE('01-JAN-'||yr) + lv dat FROM
      4  (select level - 1 lv,yr from t
      5  connect by level <= TO_DATE('31-DEC-'||yr) - TO_DATE('01-JAN-'||yr) + 1))
      6  WHERE TO_CHAR(Dat,'DY') NOT IN ('SAT','SUN')
      7  GROUP BY TO_CHAR(dat,'MON-RR');
    TO_CHAR(DAT,   COUNT(*)
    APR-10               22
    AUG-10               22
    DEC-10               23
    FEB-10               20
    JAN-10               21
    JUL-10               22
    JUN-10               22
    MAR-10               23
    MAY-10               21
    NOV-10               22
    OCT-10               21
    TO_CHAR(DAT,   COUNT(*)
    SEP-10               22
    12 rows selected.
    SQL> Edited by: AP on Jul 27, 2010 7:54 AM

  • My ipod 4 when i plug it to my pc Windows 7 had worked fine for 8 months then one day i plug it in and a message came USB device not recognized, i tried reset network settings and nothing called apple they did not know any help out there TX

    My ipod 4 when i plug it to my pc Windows 7 had worked fine for 8 months then one day i plug it in and a message came USB device not recognized, i tried reset network settings and nothing i did not install any software before this happend i called apple they did not know, any help out there TX

    Start here:
    iPhone, iPad, or iPod touch: Device not recognized in iTunes for Windows

  • My daughter created a movie using iMovie, which she has worked on for a month, when trying to save it on a jump drive she was asked to "finalize" the movie...now there is no record of it at all. Any ideas how I could try and retrieve the file?

    My daughter created a movie using iMovie 11, which she has worked on for a month. When trying to save it on a jump drive she was asked to "finalize" the movie, and while this was running (quoted 13 hours!) she received an error message. Now there is no record of it at all, I have looked in trash etc. Any ideas how I could try and retrieve the file?

    The file cannot be reloaded in iMovie using File > Open Recent  ??
    There is no trace of the file in a Spotlight search?
    The project files are not under <user>/Movies/iMovie Projects ??
    Finalizing creates small, medium and large version of the finished video. It does take a long time, but it should not destroy your project files.
    Oh, and you really MUST have a backup of your files. You can expect to lose files if you have no other copies of them.

  • Calculate number of working days in a month

    Hi All,
    I am trying to build a report to calculate the performance of a sales rep for the current month. This report has to exclude the holidays (saturday, sunday and one extra day in each month) in order get the exact performance. Could anyone suggest me on how to go about writing a Case statement which would get me the number of working days in a month excluding holidays.
    Thanks

    Hi,
    There are no direct oracle function that could be used to get the desired results.
    However you could try using something like
    SELECT COUNT( *)
    FROM
    (SELECT ROWNUM RNUM
    FROM ALL_OBJECTS
    WHERE ROWNUM <= TO_DATE('&1') - TO_DATE('&2') + 1
    WHERE TO_CHAR(TO_DATE('&2') + RNUM - 1, 'DY') NOT IN('SAT', 'SUN');
    Give the two date ranges that you want to look for with the highiest one first. i.e say for example - 01-FEB-2011 to 31-DEC-2010 would give the working days in JAN. However note that you might have to check for holidays related to that country/region (which could be added as a seperate table).
    If you need to get an extra day in addition to the weekends, please give the dates accordingly
    SQL> SELECT COUNT( *)
    2 FROM
    3 (SELECT ROWNUM RNUM
    4 FROM ALL_OBJECTS
    5 WHERE ROWNUM <= TO_DATE('01-FEB-2011') - TO_DATE('01-JAN-2011') + 1
    6 )
    7 WHERE TO_CHAR(TO_DATE('01-JAN-2011') + RNUM - 1, 'DY') NOT IN('SAT', 'SUN');
    COUNT(*)
    22

  • How to create a recurrent event on the first or last work day of the month

    The lightning calendar allows selection of the first and last day of the month for recurrent events but for business I need to use the first and last WORK day of the month (Monday - Friday) to schedule particular tasks. In the calendar preferences under 'View' I can select the days that make up the work week but this does not transfer to an option in recurrent events. Is there another way to do this or is it just not available?

    Hi there,
    do know for the UlltimateBootCD4Win? This from CD bootable WinXP-BartPEedition with additional tools gives you the ability to make such things like partitioning, backup or formatting your HDD.
    It has many more applications which help you to maintain your system without booting your original OS.
    So I think that this CD will solve your partitioning issues.
    Heres a link: www.ubcd4win.com/
    Just try it and tell me your opinion.
    Nice weekend and greetings from the sunny south ;)

  • After working fine for several months, my iPhone 5 has started dropping bluetooth connectivity for 2 to 5 seconds at a time with my Sony MDR-1RBT headphones.  The headphones work fine with other devices.  I haven't moved to ios7 yet.  Any ideas?

    After working fine for several months, my iPhone 5 has started dropping bluetooth connectivity for 2 to 5 seconds at a time with my Sony MDR-1RBT headphones.  The headphones work fine with other bluetooth devices.  I haven't moved to iOS7 yet.  Any ideas?

    What user troubleshooting have you done on the phone? The steps are restart, reset, restore from backup, restore as new. Understand that a restore will put the latest iOS on your device. It is also possible there is a hardware fault on the device and the Bluetooth is failing. Anything is possible given the scenario you describe.
    And as far as iOS 7.x is concerned, we have 5 different iPhones here at home, all with the latest iOS, a 4, 4s, 5c, and 2-5s and all are working just fine. So, a blanket statement such as the one provided by the other poster is not completely true. Others are not having any issues at all either.

  • Acrobat XI does not open - licensed copy - has been working properly for several months

    acrobat XI does not open - licensed copy - has been working properly for several months. i never did have any problems before this. was acrobat 10 with acrobat XI upgrade in November 2013 so 6-7 months of trouble free use

    I too have the same problem working property until about January or February this year...get "bad parameter' message trying to open files and then when I did the upgrade this a.m. it will not open at all, just spins and then disappears.  I had this problem about a week ago and our IT man thought he had it resolved, even then kept getting 'bad parameter' and then this a.m. right back to not opening at all.  I have Windows 7 Professional v6.1 and am wondering if it's a compatibility issue?  Will I continue to have these issued until I install Windows 8?

  • Inventory day for this month

    Hai Expert,
    can't help me please i want to use this Query :
    1. accumulation of reports to this day for this month
    2. selection criteria month
    SELECT T0.ItemCode, SUM(T0.Quantity) AS 'Qty Sales',DATEDIFF(DD,T0.DocDate,GETDATE()) as 'No. of days' FROM INV1 T0  INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode GROUP BY T0.ItemCode,T0.DocDate ORDER BY T0.ItemCode,T0.DocDate
    thanks for all

    Hai Marcella,
    i run this my Query and the result is:  item no, QtySales, No of Days
    i want add this result for find out this month with the incident until this week with the selection criteria
    i try Query Mr. Jenkins & Mr Jaya kathan same result with my Query results
    Can anyone help me ... because I have to try it several times always error
    thanks for all answear my question

  • How can i get a number of working days in a month PL/SQL

    How can i get a number of working days in a month(excluding Saturday and Sunday) in a query in PL/SQL ?

    Please do a search before posting
    sql>
    select count(*)
    from(
    select trunc(sysdate,'month')+rownum-1 dy
    from all_objects
    where rownum <= last_day(sysdate) - trunc(sysdate,'month')+1)
    where to_char(dy,'fmday') not in ('sunday','saturday');
    COUNT(*) 
    23
    Message was edited by:
            jeneesh
    Please try yourself to change the query to one that doesn't use a subquery..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • I need a receipt for the monthly $15.98 charge to my AMEX for FormsCentral.

    I need a receipt for the monthly $15.98 charge to my AMEX for FormsCentral.

    Hi,
    Thank you for contacting us.
    I request you to contact our customer support team directly at- Contact Customer Care, they will be assisting you with the payment receipt.
    Note:- Please choose the product- Acrobat.com and issue as Membership, account, payment- Click- "Still need help? contact us"- Choose contact option as- Chat.
    Regards,
    Nakul

  • Opening stock of a material for each day for a month

    Hi ,
    Is it possible to get a opening stock of a material for each day for a month . For Example for the month of Feb From 01/02/2014 to 28/02/2014 i want to see the opening stock for each day .
    Thanks .
    Message was edited by: Jürgen L

    If you give 01.02.2014 to 28.02.2014 in MB5B report, then you will got the opening stock for 01.02.2014 and closing stock for 28.02.2014...
    the MB5B report designed like that
    It will give you the opening stock for from date and closing stock for end date...
    If you want to see the opening stock per each day, then you have to give the date each date in MB5B report...
    Like as for opening for 02.02.2014, you have to enter the from date as 02.02.2014..
    You can make your own report from copy the existing program RM07MLBD and you can add you additional code...
    Make the program output will be for each day...

  • The sliders in Lightroom worked fine for several months with my Sony NEX3N but now they have no effect. I can only edit photos by changing the histogram directly.

    The sliders in Lightroom worked fine for several months with my Sony NEX3N but now they have no effect. I can only edit photos by changing the histogram directly.

    The sliders in Lightroom worked fine for several months with my Sony NEX3N but now they have no effect. I can only edit photos by changing the histogram directly.

  • Is LION OS working well for all you?

    Is LION OS working  well for all you? never thought it could be such a problem, it's the fisrt time it happens to me with an Apple product!. problems with safari, aperture, iphoto, opening/closing windows, right now is so close in performance to all windows versions than Apple high quality products at the level that all we have been expected with the release of Lion. Really dissappointed, and just hope that Apple tech suppor team solves this situation with a new sofware update.

    For most yes, For me definitely yes. I upgraded over SL, used it for a week  or more. Then updated my daughter's i5 MBP. that went well and she is happy. Then I updated my wife's MB Air. now THAT should tell you the confidence I have built in Lion. !!!

  • QIP7100 again showing activation failure (after having worked fine for a month)

    So - my newest control box (motorola QIP7100) is not working.  When I first got it it kept failing to activate and giving me the error message:  MoCATX Rate (84 Mbps) is low.  Verizon saw my message in the forum and were able to correct the issue remotely.  The set worked fine for a month, but now it is showing the same error again.  There were no changes to the TV or box, no power surges, nothing.  Does anyone know what I can do?
    Thanks

    Hello Romney68,
    I responded to the message you sent me. Let me know if this issue is still existing.
    Shamika_Vz
    Verizon Support
    Notice: Content posted by Verizon employees is meant to be informational and does not supersede or change the Verizon Forums User Guidelines or Terms or Service, or your Customer Agreement Terms and Conditions or Plan.

Maybe you are looking for

  • Mobile Me Gallery or Flickr?

    Since these are the only 2 choices on my share thing, which is better and what is the diffrence. I want to share photos some other way than email, or facebook. Thanks

  • CAll method inside layout

    Hi all,          how can we call method inside Layout

  • How do I attach a file to my email

    I am unable to attach a file - excel - to an email message that I am composing. Could somebody guide me how this is to be done?

  • IE, ActiveX and installing Flash Player

    I'm stuck in a loop. I hit a page that reqires the flash player and it doesn't show the content. Then I install the flash player, then it tells me it needs activeX. I try to install that and it never works. It keeps prompting me to install ActiveX...

  • De-activate and re-activate after HDD failure

    Hi, as above computer has a fatal HDD failure, so I can't access Photoshop Elements 11, how do I de-activate and re-activate on the new HDD install? Thanks in advance, Herman