日期:2014-05-16 浏览次数:20689 次
两个库批量修改问题
A库
员工部门
Department
DepartmentID DepartmentName
员工表
Employee
EmployeeID EmployeeStrID EmployeeName DepartmentID
B库
员工部门
Department
DepartmentID DepartmentName
员工表
Employee
EmployeeID EmployeeStrID EmployeeName DepartmentID
UPDATE B.dbo.Employee set EmployeeStrID=esi ,EmployeeName=en,DepartmentID=ISNULL((SELECT Top 1 DepartmentID FROM B.dbo.Department WHERE b.DepartmentName=dn Order by DepartmentID desc),1)
FROM B.dbo.Employee a LEFT JOIN B.dbo.Department b ON a.DepartmentID=b.DepartmentID
INNER JOIN
(SELECT EmployeeName en,EmployeeStrID esi,DepartmentName dn FROM A.dbo.Employee c LEFT JOIN A.dbo.Department d ON c.DepartmentID = d.DepartmentID) e ON a.EmployeeStrID=e.esi AND(a.EmployeeName!=e.en OR b.DepartmentName!=e.dn)