I disagree - I am looking for the correct syntax to change the where clause to first return the results of the first part of the where clause then return the first of the month of that date result. Need help with the correct syntax.
thanks,
K
-- DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0)
Modify the Where statement
Blockquote
CAST([PKDate] AS DATE) > CAST(GETDATE() - 91 AS DATE)
Blockquote
to always reflect the first day of the month for the results of the 91 day calculation - ie. if the date of 91 days back = 3/10/2016, then the actual date should be 3/1/2016
SELECT [PKDate]
, [calendar_MONTH] as MthNo
, [is_weekend]
, [is_workday]
, Day(EOMONTH([PKDate])) as DaysinMth
FROM [calendar].[dbo].[days]
WHERE CAST([PKDate] AS DATE) > CAST(GETDATE() - 91 AS DATE)
AND CAST([PKDate] AS DATE) <= CAST(GETDATE() - 1 AS DATE)
GROUP BY [PKDate], calendar_MONTH
, is_weekend
, [is_workday]