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)
 Copy column from a different column

Author  Topic 

aharvestofhealth
Yak Posting Veteran

52 Posts

Posted - 2009-04-21 : 13:08:34
I am trying to update a field in a table to = a different field in another table. I tried using the script below but it doesn't work. Can someone tell me what I'm doing wrong?

update IM_ITEM
set IM_ITEM.PROF_ALPHA_1 = PO_VEND_ITEM.COMMNT_1
from IM_ITEM, PO_VEND_ITEM

whitefang
Enterprise-Level Plonker Who's Not Wrong

272 Posts

Posted - 2009-04-21 : 13:10:09
You have no filter clause which means the update query updated all the columns of PROF_ALPHA_1 for all the rows in IM_ITEM table.

It should be
update IM_ITEM
set IM_ITEM.PROF_ALPHA_1 = PO_VEND_ITEM.COMMNT_1
from IM_ITEM, PO_VEND_ITEM WHERE IM_ITEM.ID = 1 AND PO_VEND_ITEM.ID = 1

etc
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-04-21 : 13:22:16
quote:
Originally posted by aharvestofhealth

I am trying to update a field in a table to = a different field in another table. I tried using the script below but it doesn't work. Can someone tell me what I'm doing wrong?

update IM_ITEM
set IM_ITEM.PROF_ALPHA_1 = PO_VEND_ITEM.COMMNT_1
from IM_ITEM, PO_VEND_ITEM



Specify a join condition.
Go to Top of Page

aharvestofhealth
Yak Posting Veteran

52 Posts

Posted - 2009-04-21 : 17:26:29
Ok, that did it. Thanks you guys!!!
Go to Top of Page
   

- Advertisement -