Inserting data into a temporary table

William picture William · Aug 2, 2012 · Viewed 875.4k times · Source

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?

Answer

alexsuslin picture alexsuslin · Aug 2, 2012
INSERT INTO #TempTable (ID, Date, Name) 
SELECT id, date, name 
FROM physical_table