Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2004
    Posts
    191

    Unanswered: Help with a store procedure

    I am trying to create a store procedure that look at a table and only maintain 30 worth of data only forever. The data that fall outside the 30 days need to be deleted. Can anyone help me with this?

    Thanks

    Lystra

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    create a time stamp field on your table. Then you can create a sp like...

    Create Proc Delete_Old_Junk
    As
    DELETE FROM TABLE WHERE DATE(dd,timestampfield,Getdate()) > 30
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    dateDIFF:

    DELETE FROM TABLE WHERE DATEDIFF(dd,timestampfield,Getdate()) > 30

    You will need to schedule this procedure as a job that runs once per day.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Jul 2004
    Posts
    191
    Thanks you guy, it did the trick.

    Lystra

  5. #5
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6

    datediff is what I meant

    just going to fast, spinning too many plates, too much coffee and soda, too many things going on.

    but in 99 minutes I splash down on my couch with all of my favorite indulgences.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  6. #6
    Join Date
    Jul 2004
    Posts
    191
    ...and you totally deserve it. Have a great weekend!

    Lystra

Posting Permissions

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