I have a report automation that run every first day in the month with the System Data View;
i want always get the last month, but i have problem that the syntax that the updates the two months ago too and as my sintax by the day in pickuptime
SELECT
year(getdate()) AS [Year],
'BU1' AS [Business Unit],
COUNT(*) AS JobID,
DATENAME(month, PickupTime) AS [Month]
FROM _Job
WHERE AccountID = '100000001' AND PickupTime BETWEEN GETDATE()-31 AND GETDATE()
GROUP BY DATENAME(month, PickupTime)
How to get this with 'pickuptime'?