Deleting records using ASP, ADO, and SQL

Results 1 to 3 of 3

Thread: Deleting records using ASP, ADO, and SQL

  1. #1
    Fazio82_7 Guest

    Default Deleting records using ASP, ADO, and SQL

    What&#039;s happenin, playas?<BR> small problem...<BR> I have a log (stored in SQL database) that holds events and login times of people in a specific area of my site. As a means of maintenance in the backend, I am wanting to add an easy feature that will allow the deletion of all the records in the log except the 50, 100, or 200 most recent additions. I am having some trouble coming up with the code for this, considering that the most recently added records are at the bottom of the table. <BR> Why is this a problem? because I never know how many records there are. Therefore, I don&#039;t know whether to say:<BR> delete all posts except 234-284<BR> or<BR> delete all posts except 586-636<BR>see what I&#039;m saying? If anyone&#039;s got an idea...don&#039;t be shy! (I know 4 guys who aren&#039;t)...<BR><BR>by the way...Happy Valentines Day!<BR><BR>Oh, I neglected to point out that I am using stored procedures instead of SQL statements in my page. I also do not use connected recordsets...usually just disconnected RS that are set to a command object.<BR><BR>Hope this is enough info!<BR>thanks,<BR>Fazio82_7

  2. #2
    Join Date
    Dec 1969

    Default conceptual answer only...

    No code, becuz I don&#039;t use SP&#039;s hardly at all and I know I&#039;d mess it up.<BR><BR>But anyway...<BR><BR>Suppose you did<BR><BR>SELECT TOP 50 postnumber FROM table ORDER BY postnumber DESC<BR><BR>and then grabbed the posting number of *JUST* the last record of those 50 and then used it in the next statement:<BR><BR>DELETE FROM table WHERE postnumber &#060; thePostNumberOfTheFiftiethFromBottom<BR><BR>****** **********<BR><BR>Oh! An alternative!<BR><BR>How about this:<BR><BR>DELETE FROM table <BR>WHERE postnumber NOT IN (<BR>&nbsp; &nbsp; SELECT TOP 50 postnumber FROM table ORDER BY postnumber DESC<BR>)<BR><BR>I&#039;m not sure that NOT IN is valid in SQL Server, but if it is, then you don&#039;t even need a stored procedure to make this work and work fast!<BR><BR>

  3. #3
    Fazio82_7 Guest

    Default RE: conceptual answer only...

    Bill, you&#039;re the greatest :)

Posting Permissions

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