Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL docversion query

Author  Topic 

sharepoint10
Starting Member

2 Posts

Posted - 2011-04-07 : 11:18:23
Hi - I have a table "docversion". "docversion" has a field called "version". "version" can be anything from 1 to 1000, how do I write a delete query which will delete the oldest versions, apart from the last 10. i.e if there are 80 versions I want version 70 to 80 to remain. Thanks!

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-04-07 : 11:25:32
If this gives what you want to delete,

select * from table where docversion<(select max(docversion)-10 from table)

then run

delete from table where docversion<(select max(docversion)-10 from table)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sharepoint10
Starting Member

2 Posts

Posted - 2011-04-08 : 05:03:06
Thanks!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-04-12 : 09:35:56
You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -