-1

I have table

Employee 
{
EmpId,
FirstName,
LastName,
DeptId
}

Department
{
DeptId,
DeptName,
Specialization
}

Now I had added specialization column to Employee, so now the new Employee table is:

Employee 
{
EmpId,
FirstName,
LastName,
DeptId,
Specialization
}

Now I want update script to move specialization data from Department to Employee.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Hemant Malpote
  • 891
  • 13
  • 28
  • The question is not that clear. Do you ask for a query, an update-sql or a sql-script which changes the table columns? – Tim Schmelter Nov 07 '14 at 13:53
  • possible duplicate of [UPDATE from SELECT using SQL Server](http://stackoverflow.com/questions/2334712/update-from-select-using-sql-server) – Tab Alleman Nov 07 '14 at 13:53

2 Answers2

1

You can use the update-join syntax:

UPDATE e
SET    e.Specialization = d.Specialization
FROM   Employee e
JOIN   Department d ON e.DeptId = d.DeptId
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

You can use simple nested queries;

Update Employee Ee
Set    Specialization = (SELECT Specialization
                         FROM   Department Dpt
                         Where  Dpt.DeptId = Ee.DeptId)
Nadeem_MK
  • 7,533
  • 7
  • 50
  • 61