0
SELECT HD.Login_ID
,HD.Site_Group
,HD.Incident_Number
,HD.Internet_E_mail
,HD.Assigned_Group
,HD.Assignee
,HD.Status_Reason
,HD.Description
,HD.Detailed_Decription
,HD.Priority
,HD.Submit_Date
,HD.STATUS
,HD.Entry_ID
,HD.Service_Type
,(SM.SVTDueDate - DATEDIFF(second, '1970-01-01 00:00:00', GETUTCDATE()))/60/60 AS SLM_HOURS
,(SM.SVTDueDate - DATEDIFF(second, '1970-01-01 00:00:00', GETUTCDATE()))/60 AS SLM_MINUTES
,SM.SVTDueDate
,WL.Detailed_Description AS Work_Log_Description
,WL.Work_Log_Submitter
,DATEADD(hour, 14, DATEADD(day, 25567, WL.Work_Log_Submit_Date/(60.0 * 60.0 * 24.0) - 0.25)) AS WORKLOGDATE
,(DATEDIFF(second, '1970-01-01 00:00:00', GETUTCDATE()) - WL.Work_Log_Submit_Date)/60/60 AS WORK_AGE_HOURS
,(DATEDIFF(second, '1970-01-01 00:00:00', GETUTCDATE()) - WL.Work_Log_Submit_Date)/60 AS WORK_AGE_MINUTES
,CASE HD.SLM_STATUS
WHEN 2
THEN 'Warning'
WHEN 3
THEN 'Breached'
ELSE 'Within'
END AS SLM_STATUS
,rsw.work_shift_code
,HD.InstanceId
,HD.Assignee_Login_ID
,(DATEDIFF(second, '1970-01-01 00:00:00', GETUTCDATE()) - AL.Audit_Date)/60 AS ASSIGNED_AGE_MINUTES
FROM HPD_Help_Desk AS HD
LEFT OUTER JOIN SLM_Measurement AS SM ON HD.Incident_Number = SM.ApplicationUserFriendlyID
LEFT OUTER JOIN HPD_WorkLog AS WL ON HD.Incident_Number = WL.Incident_Number
LEFT OUTER JOIN reference.dbo.SAP_worker AS rsw ON HD.Internet_E_mail = LOWER(rsw.micron_username) + '@micron.com'
LEFT OUTER JOIN HPD_HelpDesk_AuditLogSystem AS AL ON HD.Entry_ID = AL.Original_Request_ID
WHERE (HD.Assigned_Group LIKE '%MSC%')
AND (
HD.STATUS IN (
'1'
,'2'
,'3'
)
)
AND HD.Assignee IS NOT NULL
AND (
WL.Work_Log_Submit_Date IS NULL
OR WL.Work_Log_ID = (
SELECT TOP 1 (Work_Log_ID) AS Expr1
FROM HPD_WorkLog AS ML
WHERE (Incident_Number = HD.Incident_Number)
ORDER BY Submit_Date DESC
)
)
AND (
HD.Assigned_Group NOT IN (
'MIL_MSC'
,'TJP_MSC'
,'MIT_MSC'
,'MSL_MSC'
)
)
AND (HD.Assigned_Group IN (@Site_Name))
AND (
HD.Status_Reason <> 12000
OR HD.Status_Reason IS NULL
)
AND (HD.Assignee_Login_ID IN @Assignee_List)
AND (
AL.Audit_date IS NULL
OR AL.Audit_date = (
SELECT MAX(Audit_date) AS Expr1
FROM HPD_HelpDesk_AuditLogSystem AS ALS
WHERE Fields_Changed LIKE ('%Assignee%')
AND (HD.Entry_ID = Original_Request_ID)
)
AND (
SM.Create_Date IS NULL
OR SM.Create_Date = (
SELECT TOP 1 Create_Date
FROM SLM_Measurement
WHERE (ApplicationUserFriendlyID = HD.Incident_Number)
ORDER BY Create_Date DESC
)
)
)
ようこそ! – JimHawkins