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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 insert into with join subquery

Author  Topic 

cronincoder
Yak Posting Veteran

56 Posts

Posted - 2007-01-27 : 11:06:12
I'm trying to insert into table1, the result of a join between table2 and table3.

------------------------------------------
insert into table1 (val_1, val_2, val_3)

select num1, num2, num3
from table2 t2, table3 t3
where t2.num1 = t3.number_1
------------------------------------------

trying something like this but it's not working. Any ideas?

thank you

Kristen
Test

22859 Posts

Posted - 2007-01-27 : 11:10:28
Looks OK to me.

Are you getting an error?

If you just do the Select do you get rows of data, 3 columns per row?

Personally I would use JOIN syntax though:

insert into table1 (val_1, val_2, val_3)
select num1, num2, num3
from table2 AS t2
JOIN table3 AS t3
ON t2.num1 = t3.number_1

Kristen
Go to Top of Page

cronincoder
Yak Posting Veteran

56 Posts

Posted - 2007-01-27 : 11:18:54
I used you method and it worked! thanks kristen..

I must have had some wrong syntax.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-01-27 : 11:29:05
Well, I can't see any difference between the two, so maybe (assuming your example is using dummy table/column names) you missed a comma or somesuch

Kristen
Go to Top of Page
   

- Advertisement -