Hi Rebecca, I am not an expert.. below is the SQL which we use to determine if a enquiry commitment for a particular Service has failed the Target Date or met the Target Date and provides a count, I am sure other users will be able to help.
Kind Regards
Scott
SELECT commitment_status + ' - ' + cast(count(commitment_status) as varchar) as Commitment_Status,
COUNT(commitment_status) as Subtotal
FROM
(
SELECT CASE
WHEN(ec2.commit_target_time < ec2.commit_actual_time)
THEN 'Failed Target'
WHEN(ec2.commit_target_time > ec2.commit_actual_time)
THEN 'Completed on Target'
ELSE 'Error with case statement'
END Commitment_Status
FROM dbo.enquiry_commitment as ec2
INNER JOIN dbo.commitment as c ON c.commitment_code = ec2.commitment_code
INNER JOIN dbo.central_enquiry as ce ON ce.enquiry_number = ec2.enquiry_number
INNER JOIN dbo.enquiry_subject as es ON es.service_code = ce.service_code
AND es.subject_code = ce.subject_code
INNER JOIN dbo.type_of_service as tos ON tos.service_code = es.service_code
WHERE 1 = 1
AND ec2.commit_actual_time IS NOT NULL
AND tos.service_code LIKE 'PUTR'
AND c.commitment_code LIKE 'CC24'
) ilv_comm_stat
GROUP BY commitment_status
------------------------------
Scott Hill-Anderson
Senior Technical Officer
WEST LOTHIAN COUNCIL
LIVINGSTON
------------------------------
Original Message:
Sent: 08-06-2020 08:43
From: Rebecca Clark
Subject: Enquiry Commitment SQL
Hello,
I am trying to make a Dashboard that displays Enquiries as "overdue" or "still in time" based on the commitment timescale. When the commitment is unresolved but past the commitment target time then it would show as Overdue. If the Enquiry was unresolved before the target date then it would display as "Still in Time".
However there isn't an unresolved/resolved table. The commit_actual_date is the date that the commitment was resolved. Until it is resolved the commit_actual_date value is 00/00/0000 00:00:00. I need a dashboard that pulls out commitments that have a commit_actual_date value of 00/00/0000 00:00:00 on/after the commit_target_date because they must be unresolved and therefore overdue. I tried the following case in the SQL:
CASE WHEN enquiry_commitment.commit_actual_time = '00/00/0000' AND CURRENT TIMESTAMP > enquiry_commitment.commit_target_time THEN 'Late'
And got nowhere.
Does anyone have any ideas how to make this work or has made a similar dashboard using the commitment schema?
Thank you
------------------------------
Rebecca Clark
Hull City Council
HULL
------------------------------