Date Stored Procedure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GuyInTn

    Date Stored Procedure

    Hi all,

    I am trying to write a stored procedure that will delete records in a
    table that are older then 30 days. I am checking against a field that
    is called PositionDate. Can someone point me in the right direction?

    TIA
  • David Portas

    #2
    Re: Date Stored Procedure

    DELETE
    FROM Sometable
    WHERE positiondate < DATEADD(D,-30,CURRENT_TIME STAMP)

    --
    David Portas
    ------------
    Please reply only to the newsgroup
    --


    Comment

    • GuyInTn

      #3
      Re: Date Stored Procedure

      Thanks that works great. My next newbie question is, is there a way to
      have the SQL server run this automatically once a day?

      On Mon, 8 Dec 2003 21:04:46 -0000, "David Portas"
      <REMOVE_BEFORE_ REPLYING_dporta s@acm.org> wrote:
      [color=blue]
      >DELETE
      > FROM Sometable
      > WHERE positiondate < DATEADD(D,-30,CURRENT_TIME STAMP)
      >
      >--
      >David Portas
      >------------
      >Please reply only to the newsgroup[/color]

      Comment

      • David Portas

        #4
        Re: Date Stored Procedure

        Yes, you can create and schedule a job:

        Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


        --
        David Portas
        ------------
        Please reply only to the newsgroup
        --


        Comment

        • GuyInTn

          #5
          Re: Date Stored Procedure

          Thanks for the link. It was very helpful!

          On Mon, 8 Dec 2003 22:17:00 -0000, "David Portas"
          <REMOVE_BEFORE_ REPLYING_dporta s@acm.org> wrote:
          [color=blue]
          >Yes, you can create and schedule a job:
          >
          >http://msdn.microsoft.com/library/en...omate_42r7.asp
          >
          >--
          >David Portas
          >------------
          >Please reply only to the newsgroup[/color]

          Comment

          Working...