Results 1 to 2 of 2

Thread: [RESOLVED] Delete statement

  1. #1

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Resolved [RESOLVED] Delete statement

    Hello everybody,

    I need to write a delete statement to delete all the records in a table except last 100 records. I have an autogenerated ID field, so you can say delete all the records except those 100 with greatest value in ID field.

    Any idea??

    Thanks.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Delete statement

    If it is Access then this should be able to do it. If in SQL Server then just use DELETE FROM.
    Code:
    DELETE * FROM Table WHERE ID NOT IN (SELECT TOP 100 ID FROM Table ORDER BY ID DESC)
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

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



Click Here to Expand Forum to Full Width