Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 insert data from 2 temp tables into 1 temp table

Author  Topic 

mavericky
Posting Yak Master

117 Posts

Posted - 2011-08-12 : 20:17:51
Hi All,
I have these 2 temp tables:
CREATE TABLE #tmpBus1
( ScheduleID int,
HourEnd tinyint,
Name varchar(50),
Status varchar(10),
StartDT datetime,
EndDT datetime,
Active tinyint
);

and

CREATE TABLE #tmpBus2
( HE1 INT,
HE2 INT,
HE3 INT,
HE4 INT,
HE5 INT,
HE6 INT,
HE7 INT,
HE8 INT,
HE9 INT,
HE10 INT,
HE11 INT,
HE12 INT,
HE13 INT,
HE14 INT,
HE15 INT,
HE16 INT,
HE17 INT,
HE18 INT,
HE19 INT,
HE20 INT,
HE21 INT,
HE22 INT,
HE23 INT,
HE24 INT);

I have populated both with data. Now I want to select data from both of these and enter into another temp table:
CREATE TABLE #tmpBus3
( ScheduleID int,
HourEnd tinyint,
Name varchar(50),
Status varchar(10),
StartDT datetime,
EndDT datetime,
HE1 int,
HE2 int,
HE3 int,
HE4 int,
HE5 int,
HE6 int,
HE7 int,
HE8 int,
HE9 int,
HE10 int,
HE11 int,
HE12 int,
HE13 int,
HE14 int,
HE15 int,
HE16 int,
HE17 int,
HE18 int,
HE19 int,
HE20 int,
HE21 int,
HE22 int,
HE23 int,
HE24 int,
Active tinyint);
Can anyone help me?

Thanks,
Mavericky

Nikhil1home
Starting Member

23 Posts

Posted - 2011-08-12 : 20:31:28
How do you associate tmpbus2 records with corresponding tmpbus1 records? I think you need the scheduleid column already present in tmpbus2 as well. Then you can join the two temp tables on the scheduleid column and use the INSERT INTO to insert records into the third temp table.
Go to Top of Page
   

- Advertisement -