KavyaVS
asked on
How to get all the passed months in the current year.
ex;In the current year if the current month is November want to get all the passed months
(1,2,3,4,5,6,7,8,9,10) same for Feb to Dec
In the current year if the current month is Jan want to get all the Months from previous year.
Thanks
(1,2,3,4,5,6,7,8,9,10) same for Feb to Dec
In the current year if the current month is Jan want to get all the Months from previous year.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
for the above CTE approaches, if using getdate()
try this as the first line
declare @startDate as datetime = DATEADD(dd, - (DAY(getdate()) - 1), convert(date,getdate()))
(it will force @startDate to be the first of the current month, so all dates calculated will be the first of a month)