Results 1 to 2 of 2

Thread: Insert/Update in same table

  1. #1
    Join Date
    Mar 2009
    Posts
    3

    Insert/Update in same table

    Hi All,

    I have a requirement where i need to count the number of rows into a table for given date.

    following is my table

    id date
    ==== ========
    HG67 05-apr-2009
    KL90 05-apr-2009

    Lets say, the gievn date is 06-apr-2009. The table does not contain any data, the count query will return 0. In this situation, i should insert the data into table from previous day.

    I mean, after executing query, the data should look like...


    id date
    ==== ========
    HG67 06-apr-2009
    KL90 06-apr-2009
    HG67 05-apr-2009
    KL90 05-apr-2009

    I need to use previous day's data, modify the date part to current date while keeping original data as it is.

    Can some one help me to writing this query?

  2. #2
    Join Date
    Apr 2009
    Posts
    20

    Wink Using EXISTS operator.

    insert into product_details
    select P.id, TRUNC(SYSDATE)
    from product_details P
    where trunc(P.date)= trunc(sysdate-1)
    and NOT EXISTS
    (
    SELECT 1 FROM PRODUCT_DETAILS P1
    WHERE P1.ID = P.ID AND
    P.TRUNC(DATE) = TRUNC(SYSDATE)
    )

    Try this one,

    Regards,
    Srikanth.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •