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 2005 Forums
 Transact-SQL (2005)
 Copying Column from one table to another

Author  Topic 

trackjunkie
Starting Member

31 Posts

Posted - 2009-11-06 : 12:03:56
I have a table "Weights" with columns "F1" and "F2".
I have another table "item" with columns "item" and "unit weight"

Any place "Weights.F1" is equal to "item.item" I want to set "item.unit_weight" equal to "Weights.F2"

I am trying the follwoing:

Insert into item(unit_weight)
Select (F2) from Weights
Where item.item = Weights.F1

I get: The multi-part identifier "item.item" could not be bound.

Am I even close to going about this the right way.

i had a post on this yesterday but did not explain things well, so sorry for reposting a topic....


tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-06 : 12:27:32
Insert into item(item, unit_weight)
Select item.item, Weights.F2
from Weights
join item
on item.item = Weights.F1

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-11-06 : 12:28:42
It looks like you want to overwrite existing data, so an UPDATE is in order

UPDATE i
SET i.unit_weight =
w.F2
from
item i
inner join
Weights w
on
i.item = w.F1


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

trackjunkie
Starting Member

31 Posts

Posted - 2009-11-06 : 13:53:29
Ok, tried the update code provided by the last poster and it ran but effected zero rows. So I wrote a select statement:

Select item.item from item
inner join
Weights
on
item.item = Weights.F1

To test if the connection was being made and no rows were returned.

The columns are of the same type and there are definitly many shared values. What am I missing?
Go to Top of Page

trackjunkie
Starting Member

31 Posts

Posted - 2009-11-06 : 15:01:07
Never mind, i'm an idiot. It worked perfectly. Thanks.
Go to Top of Page
   

- Advertisement -