Suin Yun
Suin Yun

Reputation: 95

How to create a permanent table from joining 2 temp tables

I have two temp tables, #trial1 and #trial2, with values in them. I want to create one permanent table from joining the two existing temp tables. Here are the structures of the tables.

What I have:

table: #trial1
columns: [uID],[SVN],[IN]

table: #trial2
columns: [uID],[PLE],[TS]

What I want:

table: perm_table
columns: [SVN],[IN],[PLE],[TS]

So the two temp tables will have to join on [uID]. How can I create one permanent table from joining the two temp tables?

Upvotes: 1

Views: 1092

Answers (2)

Yogesh Sharma
Yogesh Sharma

Reputation: 50173

You seems want SELECT....INTO :

select tr1.SVN, tr1.[IN], tr1.[PLE], tr2.[TS] into perm_table
from #trial1 tr1 inner join
     #trial2 tr2
     on tr1.uid = tr2.uid;

Upvotes: 1

Mureinik
Mureinik

Reputation: 312289

You can use the select-into syntax:

SELECT [SVN], [IN], [PLE], [TS]
INTO   perm_table
FROM   #trial1 t1
JOIN   #trial2 t2 ON t1.[uID] = t2.[uID] 

Upvotes: 2

Related Questions