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
 General SQL Server Forums
 New to SQL Server Programming
 housekeeping Blobs sort of equally

Author  Topic 

Heffa
Starting Member

1 Post

Posted - 2007-07-09 : 12:59:25
Hi,
MSSQL 2005

This CTE and following Delete, deletes 1000 blobs
from every category


WITH tempdata AS (SELECT ItsAKeeper,
ROW_NUMBER() OVER (PARTITION BY Category
ORDER BY Age DESC) AS rownum,
ID FROM Imageblob WHERE ItsAKeeper = 'False')
DELETE FROM tempdata WHERE rownum > 1000;


But what I want to do is delete 1000 from the category with most
rows and 500 from the second biggest. Not shure how to do it though.

Select count(Age)
From imageblobs
Group by Catebogry

that gives me each row per category but I want to use it with the first CTE.

Any suggestions/code/help/hints are much appritiated´
My t-sql knowledge is rubbish

Cheers,

/Andreas

   

- Advertisement -