Search code examples
sqlsql-servertemp-tables

Inserting data into a temporary table


After having created a temporary table and declaring the data types like so;

CREATE TABLE #TempTable(
ID int,
Date datetime,
Name char(20))

How do I then insert the relevant data which is already held on a physical table within the database?


Solution

  • INSERT INTO #TempTable (ID, Date, Name) 
    SELECT id, date, name 
    FROM physical_table