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
 Transact-SQL (2000)
 SELECT 3 areaid and dump to another table

Author  Topic 

webmaster@aklan.net
Starting Member

2 Posts

Posted - 2007-02-15 : 13:03:01

Hi, I have a table called temp_dump with columns area1, area2, area3 and have a lookup table called area that has the IDs of area1, area2 and area3.

Now, can u help me compose a sql statement that will get an areaid of area1, area2 and area3 and insert INTO a new table?

Thank you,

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-15 : 13:19:32
select t1.someothercolumn, t2.somecolumn, t3.ausefulcolumn
into NewTableNameHere
from temp_dump as t
left join lookuptable1 as t1 on t1.fkcol = t.pkcol
left join lookuptable1 as t2 on t2.fkcol = t.pkcol
left join lookuptable1 as t3 on t3.fkcol = t.pkcol


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

webmaster@aklan.net
Starting Member

2 Posts

Posted - 2007-02-15 : 13:46:17
Thanks Dude,

It's working!

quote:
Originally posted by Peso

select t1.someothercolumn, t2.somecolumn, t3.ausefulcolumn
into NewTableNameHere
from temp_dump as t
left join lookuptable1 as t1 on t1.fkcol = t.pkcol
left join lookuptable1 as t2 on t2.fkcol = t.pkcol
left join lookuptable1 as t3 on t3.fkcol = t.pkcol


Peter Larsson
Helsingborg, Sweden

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-15 : 14:44:43
Did you write something like this?
select		t1.areaname,
t2.areaname,
t3.areaname
into NewTableNameHere
from temp_dump as t
left join area as t1 on t1.id = t.area1
left join area as t2 on t2.id = t.area2
left join area as t3 on t3.id = t.area3


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -