I have a job that sends out a spreadsheet each day. In my where clause I have the below date range so it will pull month to date:
(CAST(os.[Order Date] as date) >= DATEADD(MONTH,DATEDIFF(MONTH,0,GETDATE()),0) AND CAST(os.[Order Date] as date) <= CAST(GETDATE()-1 AS DATE))
The above works for every day except the first day of each month because I am pulling information for the previous day's records so I would need the previous month's records and this is trying to capture current month. I'm not sure if this makes sense. Is there anyway I can fix the issue to pull the previous month if it is the first day of a new month?
IF
Statement and check if it's the first day of the month using theDAY
function. Then do a different query with a differentWHERE
clause to reflect you grabbing the previous month. – Ryan Wilson