Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Selecting Last Out Of Groups

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-09-12 : 11:20:45
Josh writes "I have a table in which an employee's social security number identifies the "owner" of the record, but the record itself corresponds to a date... really a set of dates: a beginning date and an ending date, such that the format might look like:

SSN, other Record Fields, BeginDate, EndDate

Sample:

000000000,...Record Data..., 5/12/2000, 7/13/2000
000000000,...Record Data..., 7/15/2000, 8/14/2000
000000001,...Record Data..., 3/10/2000, 5/10/2000
000000001,...Record Data..., 5/11/2000, 9/21/2000
000000001,...Record Data..., 11/2/2000, 12/31/2000

And somehow, I need to select, for each SSN, the last record of a given month prior to a given date, such that if the given date were 7/14/2000, my result set would be:

000000000,...Record Data..., 5/12/2000, 7/13/2000
000000001,...Record Data..., 5/11/2000, 9/21/2000

What would my SQL look like? I, for the life of me, can't figure it out."

   

- Advertisement -