Here's my problem: a user searches for products by size. The result should show all products of the desired size (if any) plus products progressively larger and smaller until there are at least 50 undersized and 50 oversized products displayed in addition to the correctly-sized products.
The result should always show all products of a certain size; in other words, if moving to the next size up or down will result in more than 50 products, show them all - don't stop at 50.
Example: Imagine there are 25 distinct sizes with 20 products of each size. The user asks for size 12. We need to go three sizes down and three sizes up to get at least 50 in each direction. The query should return all size-12 products, plus the size 9, 10, 11, 13, 14, and 15 products. The query would return 140 products total (the 20 size-12 plus 60 above and 60 below.) Unfortunately the sizes are not nice integers like my example. They are arbitrary decimal values.
A Linq to SQL query to do this would be really cool, but plain SQL or C# is welcome, too. (My environment is C#, SQL Server 2005) Thanks