Well, OP wrote "oldest Year AND month". Not the oldest full year.CREATE PROCEDURE dbo.pDeleteOldestOrdersASSET NOCOUNT ONDECLARE @MinYearMonth DATETIME-- Get oldest orderdateSELECT @MinYearMonth = MIN(OrderDate)FROM Orders-- Calculate first day of next monthSET @MinYearMonth = DATEADD(MONTH, DATEDIFF(MONTH, '18991231', @MinYearMonth), '19000101')-- Delete all records prior to this dateDELETE FROM OrdersWHERE OrderDate < @MinYearMonth
E 12°55'05.25"N 56°04'39.16"