Heres one solution, using a Row_Number() to select the second record, but it depends on the order by
Declare @t as Table (a int, b date)
insert into @t (a,b)values('2','2012-12-21')
insert into @t (a,b)values('2','2012-12-23')
insert into @t (a,b)values('3','2012-11-23')
insert into @t (a,b)values('3','2012-11-21')
insert into @t (a,b)values('2','2012-12-21')
;With Cte as (
Select *,Row_Number() Over(Partition by a order by b desc) rn from @t
)
Select a,b from Cte where rn=2
;With Cte as (
Select *,Row_Number() Over(Partition by a order by b asc) rn from @t
)
Select a,b from Cte where rn=2
The first one does a Descending sort the second does an ascending sort so you get different values.
_________________________________________________________________________
SSC Guide to Posting and Best Practices