Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004
    Posts
    1

    Question Unanswered: Removing certain records of a SQL Server table

    Hello all,

    A little question regarding SQL Server DB's.

    I have a two tables containing customers invoices, one for the invoices header (ie: customer #, invoice date,... KEY: invoice # + invoice date) and another for the details of the invoices (ie: each invoice line details KEY: invoice # + line #). I need to periodically remove invoices older than a certain timeframe (ex: all invoices older than 48 months).

    How can I proceed?

    I am fairly new with SQL server.... Please help!

    Thanks,

    Eric

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Set up a cascading delete relationship between your invoices table and your invoice lines table. Then run this statement:

    delete
    from Invoices
    where InvoiceDate < dateadd(months, -48, getdate())

    Look up the dateadd function in Books Online to verify the syntax above.
    If it's not practically useful, then it's practically useless.

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

  3. #3
    Join Date
    Feb 2004
    Location
    San Antonio, TX
    Posts
    565
    Skunked again.

Posting Permissions

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