I am trying to write a query that will give me the number of procedures done between two specific dates during two specific hours, but only on working days. I have the script working for the dates and times, but I can't figure out how to get it so that it only includes workdays. I only want results from Monday thru Friday, excluding Saturday and Sunday from the results.
My query:
SELECT MONTH(r.LastModifiedDate) AS MONTHpreCOVID, PlacerFld2 AS MODALITY, COUNT(*) AS CountOfReportsDayTimePreCOVID
FROM [order] o
LEFT JOIN report r
ON o.reportID = r.reportID
WHERE r.LastModifiedDate >= '2019-07-01' AND r.lastmodifieddate <= '2020-06-01'
AND CAST(r.lastmodifieddate as TIME) >= '08:00:00' AND CAST(r.lastmodifieddate as TIME) <='16:59:59'
AND reportstatusID = '7'
AND r.creatorAcctID = '139'
GROUP BY MONTH(r.LastModifiedDate), PlacerFld2
ORDER BY MONTH(r.LastModifiedDate) ASC
I've tried adding something like WEEKDAY(r.lastmodifieddate) IN ('0','1','2','3','4') but that doesn't work.