Need help in writing the query to get the data for all previous months of the same year.
If today's date is July 20 2017, I need to retrieve the data for all previous months of the same year except today's date(July 20 2017).
If date is July 20 2017, data should consists of January'17 till 19 July 2017 and so on.
If date is July 21 2017, data should consists of January'17 till 20 July 2017
Thanks
DATEdatatype (removing the time) and cast back toDATETIMEif necessaryCAST(CAST(GETDATE() AS DATE) AS DATETIME). Other than that you need to provide an minimal reproducible example for us to help you. - Adwaenyth