I want to optimize the CTE in SQL Server. CTE takes so long to execute the query. However, when I use the temp table instead CTE execution is quick. Is it because of joining