When runnign this query i get this message :
The multi-part identifier "tcc.entryDate" could not be bound.
Can anybody suggest what's the problem with this query
with topOneRecord( caseId, entryDate ) as
( select table1.caseId, max(table1.entryDate) from table1
inner join table2 on table1.caseId = table2.caseId
and table2.entryDate>table1.entryDate
group by table1.caseId
)
select * into #PreviousRecord from table1
inner join topOneRecord tcc on table1.caseId = tcc.caseId
and tcc.entryDate=table1.entryDate