how to provide automatic update on a table

  • Hi All,

    I have a table that contains a date column as

    ID CreatedDate Status

    1 06/01/2009 0

    When a record is get inserted into the table the status value will be 0

    but I want to update the status by 1 after 24 hours of CreatedDate

    My Question is, if I write a update trigger(After) on that table will it work or do I need to write the Instead_of trigger.

    Thanks in Advance

    Regards

    Durgesh

  • DURGESH (5/31/2009)


    When a record is get inserted into the table the status value will be 0

    but I want to update the status by 1 after 24 hours of CreatedDate

    Hi,

    In the table, while record inserted and the status got the 0 after a day same record change to 1

    Then change the table status default like

    CREATE table ABCD

    (

    slno int,

    date1 datetime,

    status as (case when (datediff(day,date1,getdate()))>= 1 then 1 else 0 end)

    )

    ARUN SAS

  • hi,

    when status is set to 1 will the update trigger will fire

    Regards

    Durgesh

  • DURGESH (6/1/2009)


    hi,

    when status is set to 1 will the update trigger will fire

    Hi,

    No, its only show the status (when you select the table),

    Triggers for the default values are not sensible one.

    ARUN SAS

  • hi,

    As my requirement is to update other column when status is changed to 1. So, how can I achieve this

    Looking Forward

    Regards

    Durgesh

  • hi,

    then modify the table as

    CREATE table ABCD

    (

    slno int,

    date1 datetime,

    status int

    )

    and create this procedure, run this procedure in the job for every 4 hours/*as required*/

    create proc status_update

    as

    begin

    update ABCD

    set status = (case when (datediff(day,date1,getdate()))>= 1 then 1 else status end)

    where status = 0

    end

    then only trigger fired

    ARUN SAS

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply