Update Status column after specific date.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikasr2002
    New Member
    • Aug 2008
    • 3

    Update Status column after specific date.

    I have two columns in one table in database.
    1. Status
    2. DateCreated

    Now if Todays date is one year after datecreated then change the Status to deleted.

    How is it possible in SQL Server 2005. Is there any build in functionality for the same or we have to write external code ( C# ) to achive this.

    Thanks

    Vikas
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    I think this is OK
    Code:
    UPDATE tablename SET status = 'deleted' 
    WHERE datecreated < GETDATE() - 365
    or this
    Code:
    UPDATE tablename SET status = 'deleted' 
    WHERE datecreated < GETDATE() - 12 MONTH
    But double check this

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      also try:

      Code:
            UPDATE tablename SET status = 'deleted'
            WHERE datediff(yy, datecreated,GETDATE()) = 1
      Change the condition as necessary.

      -- CK

      Comment

      • vikasr2002
        New Member
        • Aug 2008
        • 3

        #4
        Originally posted by code green
        I think this is OK
        Code:
        UPDATE tablename SET status = 'deleted' 
        WHERE datecreated < GETDATE() - 365
        or this
        Code:
        UPDATE tablename SET status = 'deleted' 
        WHERE datecreated < GETDATE() - 12 MONTH
        But double check this
        This query is fine. I want it scheduled(autom ated) . There are thousand of records and daily there will be records which will qualify for this condition.
        How to schedule it in SQL Server 2005 that daily Status is changed of records who satisfy the condition.

        Thanks
        Vikas Rijhwani

        Comment

        • vikasr2002
          New Member
          • Aug 2008
          • 3

          #5
          Originally posted by ck9663
          also try:

          Code:
                UPDATE tablename SET status = 'deleted'
                WHERE datediff(yy, datecreated,GETDATE()) = 1
          Change the condition as necessary.

          -- CK
          This query is fine. I want it scheduled(autom ated) . There are thousand of records and daily there will be records which will qualify for this condition.
          How to schedule it in SQL Server 2005 that daily Status is changed of records who satisfy the condition.

          Thanks
          Vikas Rijhwani

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            Your last question would be better re-posted.
            Show your query and ask how to schedule it the way you want.

            Comment

            • ck9663
              Recognized Expert Specialist
              • Jun 2007
              • 2878

              #7
              1. Create an SP.

              2. Create a job and schedule it to run once a day.

              3. Monitor the results.

              -- CK

              Comment

              Working...