Scheduled Task List Query
=========================================================================================
SELECT
l.id,
ts.ID,
ts.DueDate
,
tp.Priority
,
tl.TaskTitle,
tc.Category
,
tsc.SubCategory
,
tf.Focus
,
l.Property
,
tl.AssetNumber,
trp.ResponsibleParty
,
tl.TargetMinValue
,
tl.TargetMaxValue
,
tl.TargetValue
,
ts.DueDate
,
CONCAT(
tl.TargetStartTime
,
‘ – ‘,
tl.TargetEndTime
) AS ScheduledTime,
tcom.CreatedDate
,
tcom.InitialResultID,
CONCAT(
”
) AS Checkbox
,
CASE
WHEN tcom.AfterActionResultID = ‘Pass’
THEN ‘Pass’
WHEN tcom.AfterActionResultID = ‘Fail’
THEN ‘Fail’
WHEN tcom.AfterActionResultID = ‘Partial Pass’
THEN ‘Partial Pass’
WHEN tcom.AfterActionResultID = ‘0’
THEN ‘NA’
END AS AfterActionResultID,
tcom.CompletedDate,
tr.Result
,
tstat.Status
,
tstat.FlagColour,
ts.SpecificFocusID
,
CASE
tstat.Status
WHEN ‘Missed’
THEN 1
WHEN ‘Overdue’
THEN 2
WHEN ‘Scheduled’
THEN 3
WHEN ‘Completed’
THEN 4
END AS Statuss
,
tcom.ActualTaskDuration AS TimeSpent
FROM
eOPS
.v_Locations
l
LEFT JOIN eOPS
.SUManageLocation
su
ON (
su
.PropertyID
= l
.id
AND su
.Status
= 3
AND su
.IsActive
= 1
)
LEFT JOIN eOPS
.EmployeeLocations
el
ON (
el
.LocationID
= l
.id
AND el
.LocationType
= 1
AND el
.Active
= 1
)
LEFT JOIN eOPS
.SchedulerTask
st
ON (
(
st
.SpecificFocusID
= l
.id
AND st
.FocusID
= ‘PR’
)
OR (
st
.SpecificFocusID
= su
.SUNumber
AND st
.FocusID
= ‘SU’
)
OR (
el
.EmpNumber
= st
.SpecificFocusID
AND st
.FocusID
= ‘EN’
)
)
LEFT JOIN eOPS
.TaskScheduler
ts
ON st
.ID
= ts
.SchedulerTaskID
LEFT JOIN eOPS
.TaskLibrary
tl
ON ts
.TaskLibraryID
= tl
.ID
LEFT JOIN eOPS
.TaskStatus
t
ON ts
.StatusID
= t
.ID
LEFT JOIN TaskPriority tp
ON tl.PriorityID
= tp.ID
LEFT JOIN TaskCategory tc
ON tl.CategoryID
= tc.ID
LEFT JOIN TaskSubCategory tsc
ON tl.SubCategoryID
= tsc.ID
LEFT JOIN TaskFocus tf
ON tl.FocusClassID
= tf.ID
LEFT JOIN TaskResponsibleParty trp
ON tl.ResponsiblePartyID
= trp.ID
LEFT JOIN TaskCompletion tcom
ON ts.ID
= tcom.TaskSchedulerID
LEFT JOIN TaskResult tr
ON tcom.InitialResultID
= tr.ID
LEFT JOIN TaskStatus tstat
ON ts.StatusID
= tstat.ID
WHERE l.id
= 11 AND( 1=1 ) GROUP BY ts.ID
THIS IS TAKING SOME TIME FOR EXECUTION. PLEASE OPTIMIZE IT
Neha Alam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.