CTE vs Temp Table vs Table Variable in SQL Server

Use a CTE to organize one statement, a temp table to store and reuse an intermediate result, or a table variable for local storage when its optimizer limitations are acceptable. See how to choose and test each option.