Query regarding dates

Hi,
Can anybody help me in formualated the single sql query for the follwing :
find out the no of days between two dates except saturday/sunday.
Please help,

look no further - BEST SOLUTION HERE
its short, it totally nls independent, and it's faster than using a connect by
select
trunc(dt2) - trunc(dt1)
   - ( next_day(trunc(dt2)-7,to_char(to_date(6,'j'),'DY')) - next_day(trunc(dt1)-7,to_char(to_date(6,'j'),'DY')) )*2/7
   + 1
   - case to_char(dt2,'Dy','nls_date_language=english') when 'Sat' then 1 else 0 end
   - case to_char(dt1,'Dy','nls_date_language=english') when 'Sun' then 1 else 0 end work_days
from ...
examples:
with t as (
select sysdate dt1, sysdate+20 dt2 from dual union all
select sysdate-30 dt1, sysdate+3 dt2 from dual union all
select sysdate-19 dt1, sysdate dt2 from dual
select dt1, dt2,
trunc(dt2) - trunc(dt1)
   - ( next_day(trunc(dt2)-7,to_char(to_date(6,'j'),'DY')) - next_day(trunc(dt1)-7,to_char(to_date(6,'j'),'DY')) )*2/7
   + 1
   - case to_char(dt2,'Dy','nls_date_language=english') when 'Sat' then 1 else 0 end
   - case to_char(dt1,'Dy','nls_date_language=english') when 'Sun' then 1 else 0 end work_days
from t
DT1       DT2        WORK_DAYS
20-MAR-08 09-APR-08         15
19-FEB-08 23-MAR-08         24
01-MAR-08 20-MAR-08         14
3 rows selected.

Similar Messages

  • " Query regarding Data transfer from Bi to BO Tool "

    Dear Friends,
                       I am having a query. I have  created a Info-cube and established the universe on the top of the Info-cube.The Dat is coming in the Bi system. When I created a new Webi-report the Data from the ino-cube in the universe is not reflecting the Webi-report .
                         Can anyone tell me the solution for the Data Load in the Webi-report .

    Hi,
    There are two ways to design universe on top of cube/Query.
    1)Olap Universe :Please go through by below link for how to create mdx universe.by this way create one connection and select cube or query and by default designer will replicate cube/query in the universe.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/903a7fc7-19e8-2d10-fa95-b050de946b61?quicklink=index&overridelayout=true
    2) Create Data federator project on top of Cube and then design universe.
    To pull data in the webi report create universe then  select objects and run the query.If data is available in the cube or query that will come in the webi report.
    I have already said webi report pull data at run time.there is no need or no way to load data in the universe or webi.
    Design a universe and create  webi or deski report on top of universe.
    For more information you can search on net can be found documents how to create report.
    Hope this helps you.
    Thanks,
    Amit

  • Query regarding data extraction

    Hello All,
    I am new to ABAP development. I have been assigned to work on a report, where I have to fetch data for a SC, which will be extracted into an flat file.
    Now my requirement is as below:
    Each shopping cart will have a number of different records. The records are of the following types
    Header – Marked with record type = “HEAD”
    Line item – Marked with record type = ”ITEM”
    Accounting line – Marked with record type = ”ACC”
    Approval record – Marked with record type = ”APP”
    Now in this manner I have to fetch the data in an single flat file. Now I am really confused how I am going to do it. I have the tables for header, item, accounting line, approval records. Now my question is am I have to 1st fetch data for header then line then accounts and approval then join this into my final internal table?? Is this the correct approach?
    I am a beginner and your help will be highly appreciated.  
    I have attached a flat file for your reference.
    Regards,
    Sarnava

    So long as you have some unique identifier between each of these tables this shouldn't be a problem. I of course can't see what data you have in the tables but lets say for example you have an account number, then you can create your flat file something like this:
    head,account123,headfield1,headfield2... etc
    item,account123,itemfld1,itemdfld2,....etc
    item,account123,itemfld1,itemdfld2,....etc
    then the same logic of course for the other two lines i.e. the first part of the line is a field which contains "head" or "item" or "acc" or "app", then the unique identifier and then the rest of the records. And you can make it comma seperated or whatever you want. The user picking this up can then also sort it.

  • Query Regarding Data transfer ( Pls Respond Quickly)

    Hi,
    I need to download the data to XML file. I have hard coded the file path in the Report Program. This Report should be shceduled for every night.
    But the problem is that since I have hard coded the path, whenever the program is deployed to production system there will be a problem regarding the file path.
    Can any body throw some light on how to avoid hard coding of the filepath ?
    Reward points are assured.
    Best  Regards
    Bhagat.

    Hey Kishan,
    In that Program the file path was hard coded. Can you let me know the alternate way so that I can avoid hard coding.
    The thing is that that report should be scheduled  for every night.
    Best Regards
    Bhagat.

  • Query regarding data loading from xls

    Hi
    I want to read data ( integers , only one column) from xls file. I donot want to load it in a table otherwise I could have tried using loader. But what I need to do is I have lakhs of rows in excel sheet and I need to pick them up in a query . I cannot create a table also as working on production . I s there any way I can pick it directly from the excel sheet as I it large volume and I cannot keep them in ( in.. clause) also .

    I want to read data ( integers , only one column)
    from xls file. I donot want to load it in a table
    otherwise I could have tried using loader. But what
    I need to do is I have lakhs of rows in excel sheet
    and I need to pick them up in a query . I cannot
    create a table also as working on production . I s
    there any way I can pick it directly from the excel
    sheet as I it large volume and I cannot keep them
    in ( in.. clause) also .Lakhs of rows!!!! You do realise that an excel spreadsheet is limited to 65536 rows? I'm right in thinking 1lakh = 100000 aren't I?

  • Query regarding date

    hello to all
    guy's in a form i m having an item i.e refdate now i want to work it like this
    that i can insert date data in ddmmyy form and when i press tab or move to other item my date should come in the
    dd/mm/yyyy format in refdate item
    plz help me out ....
    Edited by: Navdeep Kaur on Jul 27, 2009 10:08 PM

    Navdeep,
    I wrote DD/MM/RRRR not DD/MM/YYYY. If you use RRRR instead of YYYY, then the user can enter 2 digit year, and it will automatically convert to 4 digit year.
    Regards,
    Manu.
    If this answer is helpful or correct, please mark it. Thanks.

  • Query Regarding Date/Time

    hi!
    I have data in below mention form and i want to find only those records which are between "4/3/2009 16:53" and "4/7/2009 12:02". Please share select Query ?
    ---- bellow records are in date format
    4/3/2009 16:49
    4/3/2009 16:53
    4/3/2009 17:39
    4/7/2009 12:02
    4/7/2009 12:03
    4/8/2009 12:30
    4/9/2009 11:33
    DB 10g (10.2040) on unix-ita
    regards

    Thanks for your response. Problem have resolved. --irfan ahmad                                                                                                                                                                                                   

  • Query regarding Date Function

    All,
    Can I know the difference between the following two queries
    select TO_CHAR(TRUNC(sysdate),'dd-mon-rr') from dual;
    select TO_CHAR(TRUNC(sysdate),'dd-mon-yy') from dual;
    However, both the query gives the same result as '03-nov-09'.
    Regards
    ND

    ...of which century?
    SQL> var dt varchar2(10)
    SQL>
    SQL> begin
      2     :dt := '03-11-51';
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select TO_CHAR(to_date (:dt, 'dd-mm-rr'),'dd-mon-yyyy') from dual;
    TO_CHAR(TO_DATE(:DT,
    03-nov-1951
    SQL>
    SQL> select TO_CHAR(to_date (:dt, 'dd-mm-yy'),'dd-mon-yyyy') from dual;
    TO_CHAR(TO_DATE(:DT,
    03-nov-2051Don't use a two digit year...

  • Query regarding data source creation

    Hi all,
              can u plz tell me that what is the use of real time tab in extraction while creating datasource in BI 7.0?

    Hi Neha,
    If you want to get the data in a smaller intervals from the source then we will be go for this option, i.e, the data which is available in the source system till last minute will be available in the BI system for analysis purpose..
    For more information, please go thru the link below:
    http://help.sap.com/saphelp_nw04s/helpdata/en/52/777e403566c65de10000000a155106/frameset.htm
    Post back incase if you are not clear..
    Regards
    Gattu

  • Query regarding date arithmatic

    hi
    i want to write the procedure which will give me the difference of two dates in hours.
    there are two columns start_dt and end_dt and i want to calculate the difference between them in hours.
    morever i want to add functionality like if the start or end date falls on weekend(saturday & sunday) i want to subtract that whole period(which obviously will be in hours) from the total hours elapsed between two dates.
    could anyone please help me in this?
    regards,
    PD

    Diff in hours:
    (end_dt-start_dt)*24Please use the PL/SQL for SQL question.
    Nicolas.

  • Query regarding date range

    Hi I am using below query
    select count(*) from
    select M.Login_name
    , P.IND_PROD_LOGIN_ID
    , count(P.IND_PROD_LOGIN_ID) over (partition by P.IND_PROD_LOGIN_ID) cnt
    from CITI_USER_2.CCS_CUSTOMER_MAST M
    , CITI_USER_2.CCS_CUSTOMER_PROD P
    WHERE M.CUSTOMER_ID = P.CUSTOMER_ID and P.IND_PROD_LOGIN_ID not like '508127%'
    and to_char( M.CREATE_DATE , 'DD/MM/YYYY') = '16/10/2009'
    ) where cnt = 1
    and translate(Login_name,'x0123456789','x') is null
    and i got the result as 10 records but if i try to put in the date range as below
    select count(*) from
    select M.Login_name
    , P.IND_PROD_LOGIN_ID
    , count(P.IND_PROD_LOGIN_ID) over (partition by P.IND_PROD_LOGIN_ID) cnt
    from CITI_USER_2.CCS_CUSTOMER_MAST M
    , CITI_USER_2.CCS_CUSTOMER_PROD P
    WHERE M.CUSTOMER_ID = P.CUSTOMER_ID and P.IND_PROD_LOGIN_ID not like '508127%'
    and to_char( M.CREATE_DATE , 'DD/MM/YYYY') between '16/10/2009' and '17/10/2009'
    ) where cnt = 1
    and translate(Login_name,'x0123456789','x') is null
    i got the result as 653 records
    But it should be 10 only and when i check the records it is giving me wrong result.
    Can someone highlight how to use the range between the date, i need to check the number of records between the date range from 01/05/2009 to 01/10/2009

    this is all happening because of
    to_char( M.CREATE_DATE , 'DD/MM/YYYY') between '16/10/2009' and '17/10/2009'in your second query...
    that is doing a string comparision not date comparision...
    in string comparision
    check this example...
    select * from dual where '17/10/2009' > '16/10/2010'which will result a record but you might also observe that 17 th in 2009 is less than 16th of 2010. this is because here string comparision is ocurring.
    you need to change it as....
    M.CREATE_DATE between to_date('16/10/2009','DD/MM/YYYY') and to_date('17/10/2009','DD/MM/YYYY')so your query becomes...
    select count(*) from
    select M.Login_name
    , P.IND_PROD_LOGIN_ID
    , count(P.IND_PROD_LOGIN_ID) over (partition by P.IND_PROD_LOGIN_ID) cnt
    from CITI_USER_2.CCS_CUSTOMER_MAST M
    , CITI_USER_2.CCS_CUSTOMER_PROD P
    WHERE M.CUSTOMER_ID = P.CUSTOMER_ID and P.IND_PROD_LOGIN_ID not like '508127%'
    and M.CREATE_DATE between to_date('16/10/2009','DD/MM/YYYY') and to_date('17/10/2009','DD/MM/YYYY')
    ) where cnt = 1
    and translate(Login_name,'x0123456789','x') is null check your answer and get back.
    Ravi Kumar
    Edited by: ravikumar.sv on Oct 16, 2009 3:12 PM

  • Query regarding date format in BIP

    Hi
    1. Is there a way to find the date format which is set in the parameter.
    for eg.- Suppose there is a parameter Startdate mentioned in the format dd-mm-yyyy. If user chooses Startdate: dd-mm-yyyy, can we find the format, so that we can always convert it to one standard dd-mon-yyyy format?
    2. Is there a way to always convert the date to standard dd-mon-yyyy format in BI . Is there an option in BI to do this?
    Thanks
    Amit

    Amit,
    Get your date in this format in XML.
    YYYY-MM-DDThh:mm:ss+HH:MM
    Then there are lot of functions, you can apply on this to get the formatted date you wanted.

  • Query regarding data sending through VISA

    Hi,
    I have to create a program through which I send a Query from one port (1st port ) to another port (2nd port)in form of Hexadecimal array using VISA Read/Write function and when it is recieved it gives out a respone in form of another hexadecimal array to the first port.
    I have no idea how to do it.Please Help.
    Thanks.

    Duplicate post
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Query regarding the data type for fetcing records from multiple ODS tables

    hey guys;
    i have a query regarding the data type for fetcing records from multiple ODS tables.
    if i have 2 table with a same column name then in the datatype under parent row node i cant add 2 nodes with the same name.
    can any one help with some suggestion.

    Hi Mudit,
    One option would be to go as mentioned by Padamja , prefxing the table name to the column name or another would be to use the AS keyoword in your SQL statement.
    AS is used to rename the column name when data is being selected from your DB.
    So, the query  Select ename as empname from emptable will return the data with column name as empname.
    Regards,
    Bhavesh

  • Query regarding updation thru a Procedure

    Hi,I have a query regarding updation.
    1.I invoke a procedure in Oracle called submit thru my Java application.
    The submit procedure saves the XML data in the database
    and displays this data in a Front End GUI.
    2. Now,I make a change in my Java application by adding new elements to the same row.This row now contains additional XML elements.
    I would like to display the new row with the new elements in the GUI.
    What is a better option for doing the above?
    1.Delete the row being shown,save the new row with the changes in the database,and re display it?
    2.Or,Update the row dynamically and refresh?
    Any suggestions
    Thanks,

    Hi,I have a query regarding updation.
    1.I invoke a procedure in Oracle called submit thru
    my Java application.
    The submit procedure saves the XML data in the
    database
    and displays this data in a Front End GUI.
    2. Now,I make a change in my Java application by
    adding new elements to the same row.This row now
    contains additional XML elements.
    I would like to display the new row with the new
    elements in the GUI.
    What is a better option for doing the above?
    1.Delete the row being shown,save the new row with
    the changes in the database,and re display it?
    2.Or,Update the row dynamically and refresh?
    Any suggestions
    Thanks,If you delete (it seems to me yours this process is regular and frequent) and re insert the new updated one record then High water mark will cause to scan yours table which may cause to degrade the performance.AFAIK you should go with update.But hold down dont implement it as i suggested lets see what are others solution here which may be more precious then mine.
    Khurram

Maybe you are looking for

  • How to exempt a storage location from MRP run

    Hi all, How do I exempt a storage location and all its materials from MRP run. I am creating a new storage location and this should not be considered for MRP and  no idoc should be generated if a purchase order or a delivery is created from this stor

  • Automatic update stalls at conecting to update server (Mac)

    The last several times the automatic update window comes up it says "downloading firefox" on the top of the progress bar and under it it says "connecting to update server..." and it stalls right there and never gets any further no matter how long I l

  • 10.5.3 sets my PowerPC fans a humming

    After installing the latest update, the fans in my PowerPC G5 fired up and are running full bore. I thought the thing was going to explode. Any cure? The fans usually ran at low rpm and nearly silent before.

  • Getting the JScrollpane to be the correct size?

    I am having a problem with my scroll bars in the scroll pane. They are allowing me to scroll way more than I would like them to. I have added a screenshot of my problem here: http://www.minds.may.ie/~colly/problem.JPG I know that I could make the Scr

  • Solaris 10 does not start X

    Seems like a lot of people are having the same problem as i have , that X is not launched when booting up machine. I have tried to install Solaris 4 times now. With different package setups, all setups using all packages in the chosen group. All 4 ti