I am having some trouble getting my desired results, below is my logic statement.
-- logic: count the # of days between xx to yy for every GRM renewal completed in previous month (February) and then take the average (exclude holidays & weekends).
My query is below, I have been playing around with the count for weekdays. It works but I cannot apply it in the way I want it.
The result I am looking for is to identify the previous month to the current month (feb for this example) and from the range XX to YY count the # of days using (datediff) but only count weekdays.
--query 1 counts the avg cycle time (days in range)
select AVG(1.00 * DATEDIFF(DAY, xx, yy)) AS Avg_DayDiff
FROM Database1.dbo.table1
where month(datecompleted) = month(dateadd(month,-1,current_timestamp))
and year(datecompleted) = year(dateadd(month,-1,current_timestamp))
and ApprovalRequiredFrom = 'GRM'
join(
--Table Query to return # of days in previous month, including name of the day.
select CALENDAR_DATE,
DAY_NAME,
YEAR(CALENDAR_DATE) AS cal_year,
MONTH(CALENDAR_DATE) AS cal_month
from Database1.dbo.table2
where month(CALENDAR_DATE) = month(dateadd(month,-1,current_timestamp))
and year(CALENDAR_DATE) = year(dateadd(month,-1,current_timestamp))
Any Tips?
Thank you!!