How to locate nth item in an MSSQL table
Posted on 2009-05-11
I have a log table. Once table has > 10000 row in the table I need to remove earliest rows created until table contains no more than 10000 rows.
I am attempting to create delete query that will meet this requirement.
Have attempted with:
delete from logtable where pkeyid < (select top(1) pkeyid from
(select top (10000) pkeyid from logtable) order by pkeyid desc))
but MSSql report syntax errors for this attempt
Looking for corrections to my query or alternate providing same solution results