我有这样的情况需要即时搜索,但这个查询有更多的 NOT IN 检查
ALTER PROC [dbo].[DPR_SP_GetEmployeeDetailsByKeyword]
@keyword varchar(10),
@hotelId int
AS
BEGIN
SELECT EmployeeDetails.EmployeeId,EmployeeDetails.SageEmployeeId,EmployeeDetails.FirstName,EmployeeDetails.LastName
FROM EmployeeDetails
WHERE (EmployeeDetails.EmployeeId NOT IN ( SELECT EmployeeWorksIn.EmployeeId
FROM EmployeeWorksIn
WHERE EmployeeWorksIn.HotelId=@hotelId
)
AND
EmployeeDetails.EmployeeId LIKE @keyword+'%')
OR
(EmployeeDetails.EmployeeId NOT IN ( SELECT EmployeeWorksIn.EmployeeId
FROM EmployeeWorksIn
WHERE EmployeeWorksIn.HotelId=@hotelId
)
AND
OR
(EmployeeDetails.EmployeeId NOT IN ( SELECT EmployeeWorksIn.EmployeeId
FROM EmployeeWorksIn
WHERE EmployeeWorksIn.HotelId=@hotelId
)
AND
EmployeeDetails.DateOfBirth LIKE @keyword+'%')
如何优化此查询
谢谢