I have a very large table containing price history.
CREATE TABLE [dbo].[SupplierPurchasePrice](
[SupplierPurchasePriceId] [int] IDENTITY(1,1) PRIMARY KEY,
[ExternalSupplierPurchasePriceId] [varchar](20) NULL,
[ProductId] [int] NOT NULL,
[SupplierId] [int] NOT NULL,
[Price] [money] NOT NULL,
[PreviousPrice] [money] NULL,
[SupplierPurchasePriceDate] [date] NOT NULL,
[Created] [datetime] NULL,
[Modified] [datetime] NULL,
)
Per Product(Id) and Supplier(Id) I have hundreds of price records. Now there is a need to remove the bulk of the data but still keep some historic data. For each Product(Id) and Supplier(Id) i want to keep, let's say, 14 records. But not the first or last 14. I want to keep the first and last record. And then keep 12 records evenly in between the first and last. That way I keep some history in tact.
I cannot figure out a way to do this directly with a stored procedure instead of through my c# ORM (which is way too slow).