I have an interesting bit of logic that I can't seem to get my head around.
We have a Purchase table, where each Purchase is linked to a Customer and a Date. We want to pull out the Purchase that each customer made closest to the end of each month.
For instance,
CustomerID | Date
1 | 01/20/2009
2 | 01/26/2009
1 | 01/21/2009
1 | 02/02/2009
Should return....
CustomerID | Date
2 | 01/26/2009
1 | 01/21/2009
1 | 02/02/2009
Any ideas for a simple way to do this using SQL Server?