我正在尝试搜索数据库,查看它们已经打开14天但尚未调用的情况。我检查单词调用的步骤,并可以返回步骤(没有单词调用)。
如果工作调用存在,我想不返回案例(而不是返回单词调用不存在的各个步骤)。
SELECT
Support_Incident.Support_Incident_Code,
Support_Incident.Company_Name,
Support_Incident.Support_Incident_Name,
Support_Incident.Severity,
Support_Incident.MF_Status_Display,
Support_Incident.MF_Action_Owner_Display,
Support_Step.Description,
DATEDIFF(hh, Last_Updated, GETDATE()) AS 'Main'
FROM
Support_Incident
INNER JOIN Support_Step
ON Support_Incident.Support_Incident_Id = Support_Step.Support_Incident_Id
AND (Support_Step.Description NOT LIKE '%phone%'
AND Support_Step.Description NOT LIKE '%call%')
INNER JOIN Employee
ON Employee.Employee_Id = Support_Incident.Owner_Id
WHERE
(DATEDIFF(hh, Support_Incident.Display_Create_Date, GETDATE()) BETWEEN 336 AND 359
AND Support_Incident.MF_Action_Owner_Display <> 'Update'
AND Support_Incident.MF_Status_Display <> 'Closed'
AND Support_Incident.MF_Status_Display <> 'Defect'
AND Support_Incident.MF_Status_Display <> 'Enhancement'
AND Employee.Rn_Descriptor = '::sName');
答案 0 :(得分:0)
你有没有理由
(Support_Step.Description NOT LIKE'%phone%'AND Support_Step.Description NOT LIKE'%call%')
在join语句中而不在where子句中?
试试这个:
SELECT
Inc.Support_Incident_Code,
Inc.Company_Name,
Inc.Support_Incident_Name,
Inc.Severity,
Inc.MF_Status_Display,
Inc.MF_Action_Owner_Display,
Step.[Description],
DATEDIFF(hh, Last_Updated, GetDate()) AS 'Main'
FROM
Support_Incident AS Inc
INNER JOIN Support_Step AS Step ON Inc.Support_Incident_Id = Step.Support_Incident_Id
INNER JOIN Employee AS Emp ON Emp.Employee_Id = Inc.Owner_Id
WHERE
(DATEDIFF(hh, Inc.Display_Create_Date, GetDate()) BETWEEN 336 AND 359
AND Inc.MF_Action_Owner_Display <> 'Update'
AND Inc.MF_Status_Display <> 'Closed'
AND Inc.MF_Status_Display <> 'Defect'
AND Inc.MF_Status_Display <> 'Enhancement'
AND Emp.Rn_Descriptor = '::sName'
AND step.[description] Not Like '%call%');