mainrotor
asked on
I need help with a SQL Query
Hi Experts,
I need help with an update query between 2 tables without using a from/join clause.
How can I do this.
Thanks in advance,
mrotor
I need help with an update query between 2 tables without using a from/join clause.
How can I do this.
Thanks in advance,
mrotor
Here is one example
UPDATE Test1.dbo.Employee
SET DeptID = emp2.DeptID
FROM Test2.dbo.Employee as 'emp2'
WHERE
Test1.dbo.Employee.EmployeeID = emp2.EmployeeID
If two tables are involved, you cannot go without a FROM clause. Anything using a different source than the table to update requires it. With one exception: You can build an updatable view, which obfuscates the table the column is located in - but that has a lot of constraints, and I won't go into the details for that reason.
If you are trying to head towards something e.g. Oracle allows, which is
If you are trying to head towards something e.g. Oracle allows, which is
update (select ta.ca1, tb.cb2 from table1 ta join table2 tb on ta.id = tb.id /* ... */)
set ca1 = cb2
this cannot be used in MSSQL that way, and anyway it contains a FROM too :D
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also see: https://www.experts-exchange.com/articles/18499/Top-10-Ways-to-Ask-Better-Questions.html