eo
MIS
- Apr 3, 2003
- 809
SQL Server 2008
Hi
I created a query that returns the earliest record in a group, and links it as a new field back to the orig dataset, but it behaves very badly. Is there a more optimal version of such a query?
EO
Hertfordshire, England
Hi
I created a query that returns the earliest record in a group, and links it as a new field back to the orig dataset, but it behaves very badly. Is there a more optimal version of such a query?
Code:
select a.UnifiedAcctApplNumber
,a.DIM_CO_Account_SSK
,a.StatusTo
,a.TransactionDate_DATETIME
,b.TransactionDate_DATETIME as InitAwaitingCOTDate_DATETIME
from @StatusAccount a
join
(select DIM_CO_Account_SSK
,MIN(TransactionDate_DATETIME) as TransactionDate_DATETIME
from @StatusAccount
group by DIM_CO_Account_SSK) b
on a.DIM_CO_Account_SSK = b.DIM_CO_Account_SSK
where a.StatusTo = 'AwaitingCOT'
order by UnifiedAcctApplNumber, TransactionDate_DATETIME
EO
Hertfordshire, England