stillsteam
Programmer
Hi
Need some help finding out how many work days it is this week in the current month counting back from today
I will use this to calculate a salesbudget for those days
I have found in this forum solutions to how many workdays it is this week but I don´t know how to make it work for current month only.
SQL2005
Thanks in advance...
/Jonas
Need some help finding out how many work days it is this week in the current month counting back from today
I will use this to calculate a salesbudget for those days
I have found in this forum solutions to how many workdays it is this week but I don´t know how to make it work for current month only.
SQL2005
Code:
Declare @_WeekStartdate smalldatetime
SET @_WeekStartdate = dateadd(wk, datediff(Wk, 0, getdate()), 0)
((((DATEDIFF(dd, @_WeekStartDate, @EndDate) + 1) - ((DATEDIFF(dd, @_WeekStartDate, @EndDate) + 1) % 7)) / 7) * 5) + CASE WHEN (((DATEDIFF(dd, @_WeekStartDate, @EndDate) + 1) % 7) - CASE WHEN ((DATEDIFF(d, CAST('1899.12.31' AS datetime), @_WeekStartDate) % 7) + 1) = 1 THEN 1 WHEN ((DATEDIFF(d, CAST('1899.12.31' AS datetime), @_WeekStartDate) % 7) + 1) = 7 THEN 2 ELSE 0 END - CASE WHEN ((DATEDIFF(d, CAST('1899.12.31' AS datetime), @EndDate) % 7) + 1) = 1 THEN 2 WHEN ((DATEDIFF(d, CAST('1899.12.31' AS datetime), @EndDate) % 7) + 1) = 7 THEN 1 ELSE 0 END) <= 0 THEN 0 ELSE (((DATEDIFF(dd,@_WeekStartDate, @EndDate) + 1) % 7) - CASE WHEN ((DATEDIFF(d, CAST('1899.12.31' AS datetime), @_WeekStartDate) % 7) + 1) = 1 THEN 1 WHEN ((DATEDIFF(d, CAST('1899.12.31' AS datetime), @_WeekStartDate) % 7) + 1) = 7 THEN 2 ELSE 0 END - CASE WHEN ((DATEDIFF(d, CAST('1899.12.31' AS datetime), @EndDate) % 7) + 1) = 1 THEN 2 WHEN ((DATEDIFF(d, CAST('1899.12.31' AS datetime), @EndDate) % 7) + 1) = 7 THEN 1 ELSE 0 END) END AS [Weekarbetsdagar],
Thanks in advance...
/Jonas