adlan (5/29/2012)
How about
;with distinctMonths
as
(
select distinct dateadd(month,(t.[month]-1),
dateadd(year,(t.[year]-1900),0)) as MonthDate,
t.[MONTH],
t.[year]
from temp as t
),
earliestMonth
as
(
select t.PAN,min(dm.monthdate) as EarliestMonth
from distinctMonths as dm
INNER JOIN temp as t
on dm.Month = t.Month and
t.Year =...