How to get Historic Data in Oracle

Hi,
THe following query might be useful to generate the consecutive dates from given date to sysdate.
SELECT dt
FROM   ( SELECT to_date('02/19/1981','mm/dd/yyyy')+rownum-1 AS dt
       FROM    user_objects
WHERE  TRUNC(dt)<=TRUNC(SYSDATE);NOw lets consider the basic scott.emp table
The above requirement can be acheived using this query as we may get only 14 records as there are only 14 records in scott.emp table
select ( to_date('02/19/1981','mm/dd/yyyy')+rownum-1) as dt
from scott.emp If we see the scott.emp table there are 2 reocrds with empno 7499,7521 with hiredates 20-feb-81 and 22-feb-81 respectively. on pulling the historic data from19-feb-81 to 04-mar-81 as there are only 14 records in the table we need to get the sum of sal or comm as it is along with those dates in the table.
Assuming there are more than one record for the same date for the dates mentioned above , i have used the following query but could not get the desired output.
Select To_Date('02/19/1981','mm/dd/yyyy')+Rownum-1,
sum(Case When Sal>0 And Trunc(Hiredate)= (To_Date('02/19/1981','mm/dd/yyyy')+Rownum-1)
Then (Sal)
Else 0 End ) As Hist_Sal,
sum(Case When Nvl(Comm,0)>= 0 And Trunc(Hiredate)= (To_Date('02/19/1981','mm/dd/yyyy')+Rownum-1)
Then (Nvl(Comm,0))
Else 0 End) As hist_comm
From Scott.Emp
Group By To_Date('02/19/1981','mm/dd/yyyy')+Rownum-1
order by 1; I have tried the other option also and I could get the desired output.THe query goes like this:
--Success Statement
Select To_Char(Rt.Business_Date , 'Day,Mon DD,yyyy') As Business_Date ,To_Date(Rt.Business_Date) As Hist_date,
( Select sum(sal)
From Scott.Emp  Slm
Where Trunc (Hiredate) = Trunc(Rt.Business_Date)
) as hist_sal
FROM
(select ((TO_DATE('02/19/1981','mm/dd/yyyy')-1)+rnm) as business_date from (select rownum rnm from user_objects)) rt
Where
Trunc(Rt.Business_Date) Between To_Date('02/19/1981','mm/dd/yyyy') And To_Date('10/31/2012','mm/dd/yyyy')
order by Hist_date;But i want to get the historic dates/data to be genearted from scott.emp table insetead of using this logic *(select ((TO_DATE('02/19/1981','mm/dd/yyyy')-1)+rnm) as business_date from (select rownum rnm from user_objects)) rt* as written in Success Statement
As it would be helpful for my requirement ,else I need to write subqueries for all the cols i need as i have written in the above success statement.
please advise.
Regards,

sri wrote:
Hi,
THe following query might be useful to generate the consecutive dates from given date to sysdate.
SELECT dt
FROM   ( SELECT to_date('02/19/1981','mm/dd/yyyy')+rownum-1 AS dt
FROM    user_objects
WHERE  TRUNC(dt)<=TRUNC(SYSDATE);
Unless you're using Oracle 8 (or older) then it's more efficient to say:
SELECT     start_dt + LEVEL - 1     AS dt
FROM     (
          SELECT     TO_DATE ('02/19/1981', 'MM/DD/YYYY')     AS start_dt
          ,     TRUNC (SYSDATE)                           AS end_dt
          FROM     dual
CONNECT BY  LEVEL     <= 1 + (end_dt - start_dt)
;and it doesn't depend on how many rows happen to be in user_objects.
NOw lets consider the basic scott.emp table
The above requirement can be acheived using this query as we may get only 14 records as there are only 14 records in scott.emp table
select ( to_date('02/19/1981','mm/dd/yyyy')+rownum-1) as dt
from scott.emp If we see the scott.emp table there are 2 reocrds with empno 7499,7521 with hiredates 20-feb-81 and 22-feb-81 respectively. on pulling the historic data from19-feb-81 to 04-mar-81 as there are only 14 records in the table we need to get the sum of sal or comm as it is along with those dates in the table.
Assuming there are more than one record for the same date for the dates mentioned above , i have used the following query but could not get the desired output.
Select To_Date('02/19/1981','mm/dd/yyyy')+Rownum-1,
sum(Case When Sal>0 And Trunc(Hiredate)= (To_Date('02/19/1981','mm/dd/yyyy')+Rownum-1)
Then (Sal)
Else 0 End ) As Hist_Sal,
sum(Case When Nvl(Comm,0)>= 0 And Trunc(Hiredate)= (To_Date('02/19/1981','mm/dd/yyyy')+Rownum-1)
Then (Nvl(Comm,0))
Else 0 End) As hist_comm
From Scott.Emp
Group By To_Date('02/19/1981','mm/dd/yyyy')+Rownum-1
order by 1; I have tried the other option also and I could get the desired output.THe query goes like this:
--Success Statement
Select To_Char(Rt.Business_Date , 'Day,Mon DD,yyyy') As Business_Date ,To_Date(Rt.Business_Date) As Hist_date,
( Select sum(sal)
From Scott.Emp  Slm
Where Trunc (Hiredate) = Trunc(Rt.Business_Date)
) as hist_sal
FROM
(select ((TO_DATE('02/19/1981','mm/dd/yyyy')-1)+rnm) as business_date from (select rownum rnm from user_objects)) rt
Where
Trunc(Rt.Business_Date) Between To_Date('02/19/1981','mm/dd/yyyy') And To_Date('10/31/2012','mm/dd/yyyy')
order by Hist_date;But i want to get the historic dates/data to be genearted from scott.emp table insetead of using this logic *(select ((TO_DATE('02/19/1981','mm/dd/yyyy')-1)+rnm) as business_date from (select rownum rnm from user_objects)) rt* as written in Success Statement
As it would be helpful for my requirement ,else I need to write subqueries for all the cols i need as i have written in the above success statement.Sorry, I'm not sure what you're asking.
Do you want to know if there's a simpler and/or more efficient way to get the same results as the 2nd query you posted above?
Here's one way:
WITH      all_dates   AS
     SELECT     start_dt + LEVEL - 1     AS dt
     FROM     (
              SELECT     TO_DATE ('02/19/1981', 'MM/DD/YYYY')     AS start_dt
              ,             TO_DATE ('10/31/2012', 'MM/DD/YYYY')     AS end_dt
              FROM    dual
     CONNECT BY  LEVEL     <= 1 + (end_dt - start_dt)
SELECT       TO_CHAR (a.dt, 'Day, Mon DD, YYYY')     AS business_date
,       SUM (e.sal)                                AS hist_sal
FROM              all_dates  a
LEFT OUTER JOIN      scott.emp  e  ON  e.hiredate = a.dt
GROUP BY  a.dt
ORDER BY  a.dt
;For testing purposes, it would be a lot clearer if you made the end_dt something like April 5, 1981 rather than October 31, 2012.
I hope this answers your question.
If not, post the results you want from the data in scott.emp, given some reasonable date range. (I suggest Nov. 16, 1981 through Jan. 24, 1982; that includes December 3, 1981 which has 2 rows with the same hiredate.)
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002}

Similar Messages

  • How to get historical data?

    hi, experts, how to do so?
    there is a table saving task assignment.
    task no     employee to follow     start date to follow (dmy)     
    1     peter     1/3/2011     
    1     jack     1/2/2011     
    1     mary     1/1/2011     
    2     mary     1/3/2011     
    2     peter     1/1/2011     
    how to write a query to get.
    task no     employee to follow     start date to follow (dmy)     end date to follow (dmy)
    1     peter     1/3/2011     today or null
    1     jack     1/2/2011     28/2/2011
    1     mary     1/1/2011     31/1/2011
    2     mary     1/3/2011     today or null
    2     peter     1/1/2011     28/2/2011

    Forreging wrote:
    hi, experts, how to do so?
    there is a table saving task assignment.
    task no     employee to follow     start date to follow (dmy)     
    1     peter     1/3/2011     
    1     jack     1/2/2011     
    1     mary     1/1/2011     
    2     mary     1/3/2011     
    2     peter     1/1/2011     
    how to write a query to get.
    task no     employee to follow     start date to follow (dmy)     end date to follow (dmy)
    1     peter     1/3/2011     today or null
    1     jack     1/2/2011     28/2/2011
    1     mary     1/1/2011     31/1/2011
    2     mary     1/3/2011     today or null
    2     peter     1/1/2011     28/2/2011Is this you expected??
    SQL> ed
    Wrote file afiedt.buf
      1  with t
      2  as
      3  (select '1' Taskno,'Peter' ENAME,last_day(add_months(sysdate,-1))+1 AS FROMDT,last_day(add_months(sysdate,0))TO_DT
      4   from dual
      5   union all
      6   select '1','JACK',last_day(add_months(sysdate,-2))+1 ,last_day(add_months(sysdate,-1))
      7   from dual
      8   union all
      9   select '1','MARY',last_day(add_months(sysdate,-3))+1,last_day(add_months(sysdate,-2))
    10   from dual
    11   union all
    12   select '2','MARY',last_day(add_months(sysdate,-1))+1,last_day(add_months(sysdate,0))
    13   from dual
    14   union all
    15   select '1','Peter',last_day(add_months(sysdate,-3))+1,last_day(add_months(sysdate,-1))
    16   from dual)
    17  select Taskno,Ename, FROMDT,(case when to_char(fromdt,'DD-MON-YYYY')='01-MAR-2011' then sysdate else to_dt end) TO_DT
    18* from t
    SQL> /
    T|ENAME|FROMDT     |TO_DT
    -|-----|-----------|-----------
    1|Peter|01-MAR-2011|08-MAR-2011
    1|JACK |01-FEB-2011|28-FEB-2011
    1|MARY |01-JAN-2011|31-JAN-2011
    2|MARY |01-MAR-2011|08-MAR-2011
    1|Peter|01-JAN-2011|28-FEB-2011By the way I didt understand what you trying to acheive with the above query??
    Regards,
    achyut

  • How to get purchasing data from SAP R/3 to OWB (Oracle warehouse builder).

    Hi,
    My name is Pavan Tata. I work as a SAP BW developer. Here is the situation at my client place. Client decided to retire BW system and wants to replace with OWB(Oracle warehouse). In all this currently we have purhchasing application in BW production system and wants to move this application to OWB for the same type of reporting what they are getting currently.
    Here is my question:
    How to get purchasing data from SAP R/3 to OWB(Warehouse) with initial full loads and deltas mechanism in the same way as we do in BW.
    Please help on this, also send me any documentation about this if you have.
    Thanks,
    Pavan.

    Hello,
    here is a short report which converts S012 entries to strings with separator semicolon. Perhaps this will help you?
    Regards
    Walter Habich
    REPORT habitest2 LINE-SIZE 255.
    TYPES:
      strtab_t TYPE TABLE OF string.
    CONSTANTS:
      separator VALUE ';'.
    DATA:
      it_s012 LIKE s012 OCCURS 0,
      wa_s012 LIKE s012,
      strtab TYPE strtab_t,
      strele TYPE string.
    SELECT * FROM s012 INTO TABLE it_s012 UP TO 100 ROWS.
    PERFORM data_to_string
      TABLES
        strtab
      USING
        'S012'. "requires it_s012 and wa_s012
    LOOP AT strtab INTO strele.
      WRITE: / strele.
    ENDLOOP.
    *&      Form  data_to_string
    FORM data_to_string TABLES strtab TYPE strtab_t
                        USING  ittab TYPE any.
      DATA:
        h_zaehler TYPE i,
        line_str TYPE string,
        l_tabellenname(10) TYPE c,
        l_arbeitsbereichsname(10) TYPE c,
        h_string TYPE string,
        h_char(255) TYPE c.
      FIELD-SYMBOLS: <l_tabelle> TYPE ANY TABLE,
                     <l_arbeits> TYPE ANY,
                     <feldzeiger> TYPE ANY.
      CLEAR strtab.
      CONCATENATE 'IT_' ittab INTO l_tabellenname.
      ASSIGN (l_tabellenname) TO <l_tabelle>.
      CONCATENATE 'WA_' ittab INTO l_arbeitsbereichsname.
      ASSIGN (l_arbeitsbereichsname) TO <l_arbeits>.
      LOOP AT <l_tabelle> INTO <l_arbeits>.
        CLEAR: h_zaehler, line_str.
        line_str = ittab.
        DO.
          ADD 1 TO h_zaehler.
          ASSIGN COMPONENT h_zaehler OF
            STRUCTURE <l_arbeits> TO <feldzeiger>.
          IF sy-subrc <> 0. EXIT. ENDIF.
          WRITE <feldzeiger> TO h_char LEFT-JUSTIFIED.          "#EC *
          h_string = h_char.
          CONCATENATE line_str separator h_string INTO line_str.
        ENDDO.
        APPEND line_str TO strtab.
      ENDLOOP.
    ENDFORM.                    "data_to_string

  • How to get least date value

    Hi
    How to get least date value if my data is like this,
    order_id date
    121 03-mar-12
    232 30-jan-10
    343 14-may-11
    I want to pic least date value(i.e. 03-mar-12) from the list
    can any one help me on this
    Thanks,
    Lakshman
    Edited by: kolipaka on Jun 29, 2012 4:21 PM

    Hi, Lakshman,
    kolipaka wrote:
    Hi
    How to get least date value if my data is like this,
    order_id date
    121 03-mar-12
    232 30-jan-10
    343 14-may-11
    I want to pic least date value(i.e. 03-mar-12) from the list
    can any one help me on this
    Thanks,
    Lakshman
    Edited by: kolipaka on Jun 29, 2012 4:21 PM30-Jan-2010 is the earliest (least) date in that data (assuming that's a DATE column, and all the dates are in the same century). To find the earliest date, you could say:
    SELECT  MIN (dt)    AS first_date
    FROM    table_x
    ;DATE is not a good column name, so I used DT instead.
    03-Mar-2012 is the date related to the least order_id. To find that, you could say
    SELECT  MIN (dt) KEEP (DENSE_RANK FIRST ORDER BY order_id)  AS dt_or_least_order_id
    FROM    table_x;If you wanted to find several columns from the row with the earliest order_id, you could do a Top-N Query , like this:
    WITH  got_r_num  AS
        SELECT  x.*
        ,       ROW_NUMBER () OVER (ORDER BY  order_dt)   AS r_num
        FROM    table_x  x
    SELECT  *    -- or list all columns except r_num
    FROM    got_r_num
    WHERE   r_num   = 1
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • How to get changed data in ALV in Web Dynpro for ABAP

    METHOD on_data_check .
    DATA:
        node_spfli                          TYPE REF TO if_wd_context_node,
        node_sflight                        TYPE REF TO if_wd_context_node,
        itab_sflight2                        TYPE if_display_view=>elements_sflight.
      node_spfli = wd_context->get_child_node( name = if_display_view=>wdctx_spfli ).
      node_sflight = node_spfli->get_child_node( name = if_display_view=>wdctx_sflight ).
      CALL METHOD node_sflight->get_static_attributes_table
        IMPORTING
          table = itab_sflight2.
    this code is ..get all data(changed and not changed)
    but i want get changed data only, not all data.
    how to get changed data?
    Edited by: Ki-Joon Seo on Dec 27, 2007 6:04 AM

    Hi,
    To get only the changed data in the ALV grid of a WD, you need to capture the "ON_DATA_CHECK" of the ALV grid.
    To this please do the following in the ALV initialization of the ALV table settings :
        lr_table_settings->set_data_check(
                IF_SALV_WD_C_TABLE_SETTINGS=>DATA_CHECK_ON_CELL_EVENT ).
    You may also do this:
        lr_table_settings->set_data_check(            IF_SALV_WD_C_TABLE_SETTINGS=>DATA_CHECK_ON_CHECK_EVENT)
    The above two ways would depend on when do you need to check for the changed data. If you want to check the data as soon as it is entered, then use the first method. Else, use the second method.
    You need to register an EVENT HANDLER for this event.(You may do this in your VIEW or Component Controller).
    In this Event handler, you would find an importing parameter R_PARAM which is a ref type of      IF_SALV_WD_TABLE_DATA_CHECK.
    The attribute T_MODIFIED_CELLS of this interface IF_SALV_WD_TABLE_DATA_CHECK will contain the modified cells of the ALV with the old & new values.

  • How to get all data from nokia to i5s

    how to get all data from nokia E71 to i5s???

    if you can put those data in your computer then add it in iTunes. your iPhone 5s should get it thru syncing.

  • How to get the data from multiple nodes to one table

    Hi All,
    How to get the data from multiple nodes to one table.examples nodes are like  A B C D E relation also maintained
    Regards,
    Indra

    HI Indra,
    From Node A, get the values of the attributes as
    lo_NodeA->GET_STATIC_ATTRIBUTES(  IMPORTING STATIC_ATTRIBUTES = ls_attributesA  ).
    Similarily get all the node values from B, C, D and E.
    Finally append all your ls records to the table.
    Hope you are clear.
    BR,
    RAM.

  • How to get the data from pcl2 cluster for TCRT table.

    Hi frndz,
    How to get the data from pcl2 cluster for tcrt table for us payroll.
    Thanks in advance.
    Harisumanth.Ch

    PL take a look at the sample Program EXAMPLE_PNP_GET_PAYROLL in your system. There are numerous other ways to read payroll results.. Pl use the search forum option & you sure will get a lot of hits..
    ~Suresh

  • How to get the data from Pooled Table T157E.

    Hi Experts,
    How to get the data from Pooled Table T157E.
    Any help.
    Thanks in Advance,
    Ur's Harsha.

    create some internal table similar to T157E and pass all data as per SPRAS.
    After that use internal table in your program as per the requirement.
    Regds,
    Anil

  • How to get the data from mysql database which is being accessed by a PHP application and process the data locally in adobe air application and finally commit the changes back in to mysql database through the PHP application.

    How to get the data from mysql database which is being accessed by a PHP application and process the data locally in adobe air application and finally commit the changes back in to mysql database through the PHP application.

    If the data is on a remote server (for example, PHP running on a web server, talking to a MySQL server) then you do this in an AIR application the same way you would do it with any Flex application (or ajax application, if you're building your AIR app in HTML/JS).
    That's a broad answer, but in fact there are lots of ways to communicate between Flex and PHP. The most common and best in most cases is to use AMFPHP (http://amfphp.org/) or the new ZEND AMF support in the Zend Framework.
    This page is a good starting point for learning about Flex and PHP communication:
    http://www.adobe.com/devnet/flex/flex_php.html
    Also, in Flash Builder 4 they've added a lot of remote-data-connection functionality, including a lot that's designed for PHP. Take a look at the Flash Builder 4 public beta for more on that: http://labs.adobe.com/technologies/flashbuilder4/

  • HOW TO TRANSFER HISTORICAL DATA FROM ONE ACCOUNT TO ANOTHER

    제품 : FIN_GL
    작성날짜 : 2006-05-29
    HOW TO TRANSFER HISTORICAL DATA FROM ONE ACCOUNT TO ANOTHER
    =============================================================
    PURPOSE
    특정 기간의 Balance 를 Account 별로 Transfer 하는 방법에 대해 알아 보도록 한다.
    Explanation
    GL 의 Mass Maintenance 기능을 이용하면 한 Account 에서 다른 Account 로 혹은 Multiple Account 에서 다른 하나의 Account 로 Balance 를 이동 시킬 수 있다.
    1. GL Responsibility 에서 Other> Mass Maintenance 를 선택한다.
    2. Move/Merge 작업을 위한 Request Name 과 Description을 입력한다.
    3. Request Type 으로 Move 혹은 Merge 를 선택한다.
    4. source-to-target account 를 위해 line number 를 입력한다.
    5. LOV 에서 source Account 를 선택하여 입력한다.
    모든 Account 는 enable 상태여야 한다.
    6. target account 역시 LOV에서 선택하여 입력한다.
    7. 지정한 작업을 수행 하기 전에 먼저 확인 작업을 할 수도 있다.
    8. 작업한 내용을 저장한다.
    9. Move/Merge request 를 수행한다.
    Example
    N/A
    Reference Documents
    Note. 146050.1 - How to Transfer Historical Data from One Account to Another

    Follow the directions here:
    http://support.apple.com/kb/HT2109

  • How to get the date of first day of a week for a given date

    Hi gurus
    can any one say me how to get the date of first day(date of Sunday) of a week for a given date in a BW transformations. For example for 02/23/2012 in source i need to get 02/19/2012(Sunday`s date) date in the result. I can get that start date of a week using  BWSO_DATE_GET_FIRST_WEEKDAY function module. But this function module retrieves me the  start date as weeks monday(02/20/2012) date. But i need sundays(02/19/2012) date as the start date. So it would be really great if anyone sends me the solution.
    Thanks
    Rav

    Hi,
    The simplest way would be to subtract 1 from the date date which you are already getting in transformation routine, but instead of doing that subtraction manually which might need bit of errort, you can simply use another FM to subtract 1 from given date.
    RP_CALC_DATE_IN_INTERVAL
    Regards,
    Durgesh.

  • How to Get Missing Dates for Each Support Ticket In My Query?

    Hello -
    I'm really baffled as to how to get missing dates for each support ticket in my query.  I did a search for this and found several CTE's however they only provide ways to find missing dates in a date table rather than missing dates for another column
    in a table.  Let me explain a bit further here -
    I have a query which has a list of support tickets for the month of January.  Each support ticket is supposed to be updated daily by a support rep, however that isn't happening so the business wants to know for each ticket which dates have NOT been
    updated.  So, for example, I might have support ticket 44BS which was updated on 2014-01-01, 2014-01-05, 2014-01-07.  Each time the ticket is updated a new row is inserted into the table.  I need a query which will return the missing dates per
    each support ticket.
    I should also add that I DO NOT have any sort of admin nor write permissions to the database...none at all.  My team has tried and they won't give 'em.   So proposing a function or storable solution will not work.  I'm stuck with doing everything
    in a query.
    I'll try and provide some sample data as an example -
    CREATE TABLE #Tickets
    TicketNo VARCHAR(4)
    ,DateUpdated DATE
    INSERT INTO #Tickets VALUES ('44BS', '2014-01-01')
    INSERT INTO #Tickets VALUES ('44BS', '2014-01-05')
    INSERT INTO #Tickets VALUES ('44BS', '2014-01-07')
    INSERT INTO #Tickets VALUES ('32VT', '2014-01-03')
    INSERT INTO #Tickets VALUES ('32VT', '2014-01-09')
    INSERT INTO #Tickets VALUES ('32VT', '2014-01-11')
    So for ticket 44BS, I need to return the missing dates between January 1st and January 5th, again between January 5th and January 7th.  A set-based solution would be best.
    I'm sure this is easier than i'm making it.  However, after playing around for a couple of hours my head hurts and I need sleep.  If anyone can help, you'd be a job-saver :)
    Thanks!!

    CREATE TABLE #Tickets (
    TicketNo VARCHAR(4)
    ,DateUpdated DATETIME
    GO
    INSERT INTO #Tickets
    VALUES (
    '44BS'
    ,'2014-01-01'
    INSERT INTO #Tickets
    VALUES (
    '44BS'
    ,'2014-01-05'
    INSERT INTO #Tickets
    VALUES (
    '44BS'
    ,'2014-01-07'
    INSERT INTO #Tickets
    VALUES (
    '32VT'
    ,'2014-01-03'
    INSERT INTO #Tickets
    VALUES (
    '32VT'
    ,'2014-01-09'
    INSERT INTO #Tickets
    VALUES (
    '32VT'
    ,'2014-01-11'
    GO
    GO
    SELECT *
    FROM #Tickets
    GO
    GO
    CREATE TABLE #tempDist (
    NRow INT
    ,TicketNo VARCHAR(4)
    ,MinDate DATETIME
    ,MaxDate DATETIME
    GO
    CREATE TABLE #tempUnUserdDate (
    TicketNo VARCHAR(4)
    ,MissDate DATETIME
    GO
    INSERT INTO #tempDist
    SELECT Row_Number() OVER (
    ORDER BY TicketNo
    ) AS NROw
    ,TicketNo
    ,Min(DateUpdated) AS MinDate
    ,MAx(DateUpdated) AS MaxDate
    FROM #Tickets
    GROUP BY TicketNo
    SELECT *
    FROM #tempDist
    GO
    -- Get the number of rows in the looping table
    DECLARE @RowCount INT
    SET @RowCount = (
    SELECT COUNT(TicketNo)
    FROM #tempDist
    -- Declare an iterator
    DECLARE @I INT
    -- Initialize the iterator
    SET @I = 1
    -- Loop through the rows of a table @myTable
    WHILE (@I <= @RowCount)
    BEGIN
    --  Declare variables to hold the data which we get after looping each record
    DECLARE @MyDate DATETIME
    DECLARE @TicketNo VARCHAR(50)
    ,@MinDate DATETIME
    ,@MaxDate DATETIME
    -- Get the data from table and set to variables
    SELECT @TicketNo = TicketNo
    ,@MinDate = MinDate
    ,@MaxDate = MaxDate
    FROM #tempDist
    WHERE NRow = @I
    SET @MyDate = @MinDate
    WHILE @MaxDate > @MyDate
    BEGIN
    IF NOT EXISTS (
    SELECT *
    FROM #Tickets
    WHERE TicketNo = @TicketNo
    AND DateUpdated = @MyDate
    BEGIN
    INSERT INTO #tempUnUserdDate
    VALUES (
    @TicketNo
    ,@MyDate
    END
    SET @MyDate = dateadd(d, 1, @MyDate)
    END
    SET @I = @I + 1
    END
    GO
    SELECT *
    FROM #tempUnUserdDate
    GO
    GO
    DROP TABLE #tickets
    GO
    DROP TABLE #tempDist
    GO
    DROP TABLE #tempUnUserdDate
    Thanks, 
    Shridhar J Joshi 
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • How to get the date for the first monday of each month

    Dear Members,
    How to get the date for the first monday of each month.
    I have written the following code
    SELECT decode (to_char(trunc(sysdate+30 ,'MM'),'DAY'),'MONDAY ',trunc(sysdate+30 ,'MM'),NEXT_DAY(trunc(sysdate+30 ,'MM'), 'MON')) FROM DUAL
    But it look bith complex.
    Abhishek
    Edited by: 9999999 on Mar 8, 2013 4:30 AM

    Use IW format - it will make solution NLS independent. And all you need is truncate 7<sup>th</sup> day of each month using IW:
    select  sysdate current_date,
            trunc(trunc(sysdate,'mm') + 6,'iw') first_monday_the_month
      from  dual
    CURRENT_D FIRST_MON
    08-MAR-13 04-MAR-13
    SQL> Below is list of first monday of the month for this year:
    with t as(
              select  add_months(date '2013-1-1',level-1) dt
                from  dual
                connect by level <= 12
    select  dt first_of_the_month,
            trunc(dt + 6,'iw') first_monday_the_month
      from  t
    FIRST_OF_ FIRST_MON
    01-JAN-13 07-JAN-13
    01-FEB-13 04-FEB-13
    01-MAR-13 04-MAR-13
    01-APR-13 01-APR-13
    01-MAY-13 06-MAY-13
    01-JUN-13 03-JUN-13
    01-JUL-13 01-JUL-13
    01-AUG-13 05-AUG-13
    01-SEP-13 02-SEP-13
    01-OCT-13 07-OCT-13
    01-NOV-13 04-NOV-13
    FIRST_OF_ FIRST_MON
    01-DEC-13 02-DEC-13
    12 rows selected.
    SQL> SY.

  • How to get the Date in a particular format?

    Hi,
    How to get the Date in the below format? I will be passing the year in my method..
    2/10/2003 9:46:52 PM
    D/M/YYYY H:M:S A
    public Date getDate (String year) {
    Here i want to get the Date in this format
    2/10/<Passed Year> 9:46:52 PM
    Thanks

    This is my code
    public static Date getCalendar(Calendar calendar,int getYear) {
    String      formatted_date="";
         int year = getYear;
         int month = calendar.get(Calendar.MONTH+1);
         int day = calendar.get(Calendar.DATE);
         int hour = calendar.get(Calendar.HOUR);
         int min = calendar.get(Calendar.MINUTE);
         int sec = calendar.get(Calendar.SECOND);
         int am_pm =calendar.get(Calendar.AM_PM);
         formatted_date = month+"/"+day+"/"+year+" "+hour+":"+min+":"+sec+" PM";
         System.out.println("formatted_date is "+formatted_date);     
         o/p : formatted_date is 1/4/2006 1:44:21 PM
         SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    //     DateFormat dateFormat =DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
         Date passdate = new Date();
         try {
              passdate = dateFormat.parse(formatted_date);
         } catch (ParseException e) {
              System.out.println("Invalid Date Parser Exception "+e.getLocalizedMessage()+"DateFormat is "+dateFormat);
              System.out.println("The Date inside the function is "+passdate+"and the year passed is "+year);
    o/p : The Date inside the function is Sat Apr 01 00:00:00 IST 2006and the year passed is 2006
         return passdate;
    Expected O/P is 3/1/2006 1:44:12 PM
         }

Maybe you are looking for

  • Leopard For My G4?

    I have a MDD G4 running Tiger and am considering going to Leopard. I have the minimum requirement 867DP.I have 2 hard drives...the main is 60gig with Tiger and the other is a self-installed Seagate 120 gig partitioned into 2, one for data and the oth

  • Merging Clips - how to keep 50fps

    I have 2 quicktime-clips, both 50fps, same bandwith-rate and size. When I put them together in Quicktime and export the output changes to a lower as 50 fps. Is there an option in quicktime to keep the current fps settings?

  • Logic Express 9 will not install.

    Hi all, I just bought a Macbook Pro 17" with Logic Express 9 and the program will not install and comes up with with "Errors where detected and installation has stopped. Contact the manufacture." It would get through to about 20 - 30% when it fails.

  • Windows vista 32 Bit Ultimate. Black screen after installing drivers B-Camp

    I installed windows vista Ultimate 32 bit on my 2.26ghz mac mini 2gb ram. after installing vista and setting up my account, i installed the drivers from the apple CD that came with the mac. it installed all the drivers and requested me to reboot, so

  • Netweaver  XI Integration between different servers

    We are planning to conect the network between Client/Server which is java based system to SAP XI.      and Mainframes to sap XI. Can you please let me know how to Integrate between them ?