Here is a fully working example:
create table temp (id int,name varchar(20),code int, morecolumns int)
create table #temp(id int,name varchar(20),code int)
insert #temp values(1,'Thomas Clausen',1)
select * into xx_temp from #temp
declare @col varchar(max) , @sql varchar(max) = ''
select @col = coalesce(@col + ',', '')+ '[' + name + ']'
from tempdb.sys.columns
where object_id = object_id('tempdb..#temp');
select @sql='insert temp(' + @col+ ') select '+@col+' from xx_temp'
exec (@sql)
go
drop table xx_temp
There is a drawback, this example will create a table xx_temp and drop it right after executing. So the script should not execute more than once at a time. The table xx_table is created to get the data into the same scope inside the dynamic sql