Problem with query using CTE

  • 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

  • If you are doing "SELECT *" into a #temp table, all the column names need to be unique.

    In this case both your tables contain a column named "caseID", therefore temp table creation will fail due to duplicate column names.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply