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 Administration
 Need to update table

Author  Topic 

rdev.theo
Starting Member

5 Posts

Posted - 2011-07-19 : 14:54:43
Hi, I have 2 tables which have one common field, I need to ensure that few rows are updated as in table 1 in table 2:
for eg:

Table 1
Common_Field Name
1234 Chandan
4321 Kiran

Table 2
Common_Field Name
1234 Raj
4321 Kiran

Intended Result:
Common_Field Name
1234 Chandan
4321 Kiran

Please let me know, Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-19 : 15:00:02
So the Name in table2 should be updated to the Name of table1 if Common_field is matching and Names are different?
Try:
update t2
set Name = t1.Name
from table2 as t2
join table1 as t1 on t1.Common_Field = t2.Common_Field
where t2.Name <> t1.Name


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

rdev.theo
Starting Member

5 Posts

Posted - 2011-07-19 : 15:55:48
Yes what you have understood is correct...
Tried following I get and error as "SQL command not properly ended"

any reasons?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-19 : 17:12:47
Oh!
You have posted in a MS SQL Server forum but the error is ORACLE, so I dont know.
Please try http://www.dbforums.com/oracle/


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -