views:

659

answers:

5

I have to update value based on values from another table:

update OracleOb..NS.myTable set name = (select name from myTable1 where id = 1)
   where id = 1

here the SQL has some problem. How can I get value from myTable1 and set it to myTable?

I am using MS SQL 2005.

Sorry I have to edit this question again. The table myTable is a linked object of Oracle table. I tried the suggested answer but I got error message:

 The OLE DB provider "OraOLEDB.Oracle" for linked server "OracleOb" reported an error. The provider reported an unexpected catastrophic failure.
+6  A: 
UPDATE m 
SET m.name = m1.name
FROM MyTable m
    JOIN MyTable1 m1 ON m.id = m1.id
WHERE m.id = 1
AdaTheDev
A: 
-- Remove the where clause if you are trying to update more than just the 1 record.

UPDATE  MyTable
SET     Name = B.Name
FROM    MyTable A JOIN MyTable1 B ON A.ID = B.ID
WHERE   ID = 1
Scott Ivey
A: 

You can use a join like:

update myTable set name = myTable1.name from myTable inner join myTable1 on myTable.id = myTable1.id myTable.where id = 1

A: 
update myTable set 
    name = t1.name
from myTable as t
    join myTable1 as t1 on t.id = t1.id
    where t.id = 1
Remus Rusanu
A: 

Here is a update by checking other TWO tables :

UPDATE C SET C.username = A.UserName FROM Staged.ClientEmployee C JOIN [dbo].[TempE] E ON C.id = E.Fax AND C.ssn = E.SSN JOIN NW_SEFL.CFG.Account A ON A.EmployeeId = E.EmployeeId WHERE E.Fax = @StageEmpID

jim