1

请参阅以下查询:

Update Employee
Set AccountManagerId = a.AM_ID
FROM Employee e INNER JOIN AccountManager a on e.Id = a.Id
WHERE

**努力构造下面的部分(需要添加到where子句中)**

If a.Department is not null then [FOLLOWING NEEDS TO BE ADDED TO WHERE CLAUSE] (e.Department = a.department)

努力将其添加到 where 子句。因此,如果部门不为 NULL,则将其添加到 WHERE 子句

4

3 回答 3

0

你不能这样做:

Update Employee
Set AccountManagerId = a.AM_ID,
e.Department = a.department
FROM Employee e INNER JOIN AccountManager a on e.Id = a.Id
WHERE
a.Department IS NOT NULL
于 2013-03-06T11:30:40.150 回答
0

为什么不向联接添加另一个条件?

我相信这将实现您的意图,仅更新员工与具有部门的匹配客户经理。

UPDATE Employee
SET AccountManagerId = a.AM_ID
FROM Employee e 
INNER JOIN AccountManager a 
ON e.Id = a.Id
AND
e.Department = a.Department
于 2013-03-06T11:30:53.930 回答
0
Update Employee
Set AccountManagerId = a.AM_ID
FROM Employee e INNER JOIN AccountManager a on e.Id = a.Id
WHERE ((a.Department IS NULL) || (e.Department = a.department))
于 2013-03-06T11:33:42.170 回答