I have a query in SQL Server which returns me the data of 1 ago
SELECT titulo, categoria
FROM posts
WHERE dataCadastro BETWEEN DATEADD(year,-1,GETDATE()) AND GETDATE()
ORDER BY dataCadastro DESC";
The problem is that I need this query to also return all data for every month in the range. I want the results to come from first day of last month in the range to the current date.
The problem is that the results are coming exactly 1 year ago so the results that are coming in come from 22/01/2017. I need the data to come in 01/01/2017 .
Is DATEADD
best in this case?