SELECT $partition.OrderDetailDatePartitionFunction(o.OrderDetailDate) AS [Partition Number] FROM dbo.OrderDetail AS o WHERE o.OrderDetailKey = (SELECT MIN(o1.OrderDetailKey) FROM dbo.OrderDetail AS o1 WHERE o1.OrderDetailDate = (SELECT min(o2.OrderDetailDate) FROM dbo.OrderDetail AS o2)) ;