I am still learning SQL so please bare that in mind. I have a query that returns me the average days for a specific range, although my range does not account for weekends & holidays. Holidays may be a little tricky but how do I exclude weekends from my range?
For example I have a range 02-01-18 to 02-15-18 where the datediff is 14 days, but how do I get SQL to identifying which days in that range were weekends and if they were to exclude them from my datediff?
My query is
SELECT
AVG(1.00 * DATEDIFF(DAY, xx, yy)) AS DayDiff
FROM
datebase1.dbo.table1
WHERE
MONTH(datecompleted) = MONTH(DATEADD(month, -1, current_timestamp))
AND YEAR(datecompleted) = YEAR(DATEADD(month, -1, current_timestamp))
AND ApprovalRequiredFrom = 'pp'
I do have a calendar I can source which tells me the date and the name of the day, but I want to avoid having to do this. I want to be able to exclude the weekends from my range to get me a more accurate result.
Thanks