我正在查询两个表并将它们连接到人名上。我正在尝试制作过去一个月内未填写表格的所有员工。我遇到的问题是,当人们列出他们的简称(乔而不是约瑟夫,或者迈克而不是迈克尔)时,我会收到重叠的名字。即使他们使用了他们的简称,我如何仍然可以生成不重叠的人员列表?
这是我现在的查询:
SELECT DISTINCT ge.employeeNo,
(ge.firstName + ' ' + ge.lastName) AS empName,
ge.email
FROM dbo.hist_Employees ge
INNER JOIN dbo.ctrl_Sites cs ON ge.locationID = cs.ID
WHERE (ge.firstName + ' ' + ge.lastName) NOT IN
(SELECT sc.recordedBy
FROM GRSTOPS.dbo.hist_StopCard sc
INNER JOIN dbo.ctrl_Area a ON sc.area = a.ID
INNER JOIN dbo.ctrl_Site s ON a.site = s.ID
WHERE sc.recorded BETWEEN '10/01/2013' AND '10/30/2013'
AND s.code = 'gre')
AND cs.Abbreviation = 'gre'
AND ge.employmentStatus = 1
AND ge.primaryDept <> 3