• JOIN #Temp ON ...
    Then you can reference it further down. Same as any other table.

    You can't say
    FROM Customers inner join OrderDetails on Customers.ID = Orders.CustomerID, same with temp tables.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass