在创建临时表并像这样声明数据类型之后;

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

然后,我如何插入已经在数据库中的物理表上持有的相关数据?


当前回答

insert #temptable
select idfield, datefield, namefield from yourrealtable

其他回答

SELECT * 
INTO #TempTable
FROM table
insert #temptable
select idfield, datefield, namefield from yourrealtable

创建临时表后,只需执行普通的INSERT INTO () SELECT FROM

INSERT INTO #TempTable (id, Date, Name)
SELECT t.id, t.Date, t.Name
FROM yourTable t
INSERT INTO #TempTable(ID, Date, Name)
SELECT OtherID, OtherDate, OtherName FROM PhysicalTable
SELECT  ID , Date , Name into #temp from [TableName]