昨天我在这个 SQL 语句上得到了帮助,它工作得非常好......现在我正在尝试使用这个查询中的数据来更新不同表上的两列。
这是我的查询:
SELECT x.TechID,
Count(*) AS cnt,
tblEmployeeData.LName,
tblEmployeeData.Pernr,
tblEmployeeData.Occurrences,
tblEmployeeData.Standing
FROM tblEmployeeData
INNER JOIN tblOccurrence AS x
ON tblEmployeeData.TechID = x.TechID
WHERE ( ( ( x.OccurrenceDate ) BETWEEN Dateadd("m", -6, Date()) AND Date() )
AND ( ( EXISTS (SELECT *
FROM tblOccurrence AS y
WHERE y.TechID = x.TechID
AND Dateadd ("d", -1, x.[OccurrenceDate]) = y.[OccurrenceDate]) ) = False ) )
GROUP BY x.TechID,
tblEmployeeData.LName,
tblEmployeeData.Pernr;
我想要做的是获取结果并更新 tblEmployeeData 两列。一列 (tblEmployeeData.Occorrences) 将是由 'cnt' 表示的值......然后是困难的部分...... tblEmployeeData.Standing 列将使用来自 'cnt' 的值进行更新,如下所示:
0-3 = "Good"
4-5 = "Verbal Warning"
6-7 = "Written Warning"
8 = "Final Written Warning"
9+ = "Termination"
这已经是一个很大的 SQL 语句了,这超出了我的想象!