I have a table that contains multiple records for each day of the month, over a number of years. Can someone help me out in writing a query that will only return the last d
In SQL Server, this is how I usually get to the last day of the month relative to an arbitrary point in time:
select dateadd(day,-day(dateadd(month,1,current_timestamp)) , dateadd(month,1,current_timestamp) )
In a nutshell:
Voila! You've the the last day of the month containing your reference point in time.
Getting the 1st day of the month is simpler:
select dateadd(day,-(day(current_timestamp)-1),current_timestamp)
Stripping off/normalizing the extraneous time component is left as an exercise for the reader.