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 temp table to sql table

Author  Topic 

mavericky
Posting Yak Master

117 Posts

Posted - 2011-08-12 : 18:11:40
Hi,
I have a temp table with a set of values. I want to insert this data into a sql table.
my temp table:
CREATE TABLE #tmpBus4
( 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 want to insert data into this table. I can come up with the values of first 6 columns. I want to pick the rest of the values from temp table.
[base_sg_operational].[dbo].[Schedule]
([ScheduleID]
,[HourEnd]
,[Name]
,[Status]
,[StartDT]
,[EndDT]
,[HE1]
,[HE2]
,[HE3]
,[HE4]
,[HE5]
,[HE6]
,[HE7]
,[HE8]
,[HE9]
,[HE10]
,[HE11]
,[HE12]
,[HE13]
,[HE14]
,[HE15]
,[HE16]
,[HE17]
,[HE18]
,[HE19]
,[HE20]
,[HE21]
,[HE22]
,[HE23]
,[HE24])

Thanks,
Mavericky

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-12 : 18:39:33
How can you associate the rows together?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mavericky
Posting Yak Master

117 Posts

Posted - 2011-08-12 : 19:07:17
Okay, if the structure of Schedule table is this, can you help me?
[base_sg_operational].[dbo].[Schedule]
([HE1]
,[HE2]
,[HE3]
,[HE4]
,[HE5]
,[HE6]
,[HE7]
,[HE8]
,[HE9]
,[HE10]
,[HE11]
,[HE12]
,[HE13]
,[HE14]
,[HE15]
,[HE16]
,[HE17]
,[HE18]
,[HE19]
,[HE20]
,[HE21]
,[HE22]
,[HE23]
,[HE24])

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-12 : 19:11:06
Maybe this is what you want:

INSERT INTO Schedule
SELECT @var1, @var2, @var3, @var4, @var5, @var6, HE1, ..., HE24
FROM #tmpBus4

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mavericky
Posting Yak Master

117 Posts

Posted - 2011-08-12 : 20:15:03
Thanks!!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-13 : 13:43:19
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -