SQL Server 2012 introduced one new TSQL EOMONTH to return the last day of the month that contains the specified date with an optional offset.
In this post, I am sharing syntax and one example to find first Sunday of the next month using EOMONTH.
The Database Administrator many times required to execute database maintenance script at every first Sunday of the next month, so I have prepared this script using EOMONTH.
The Syntax of EOMONTH:
EOMONTH ( start_date [, month_to_add ] )
Script to find first Sunday of the Next Month:
First, create sample table with data:
CREATE TABLE tbl_Test_EOMONTH
INSERT INTO tbl_Test_EOMONTH VALUES ('2015-12-20')
INSERT INTO tbl_Test_EOMONTH VALUES ('2015-11-08')
INSERT INTO tbl_Test_EOMONTH VALUES ('2015-10-16')
INSERT INTO tbl_Test_EOMONTH VALUES ('2015-09-26')
INSERT INTO tbl_Test_EOMONTH VALUES ('2016-01-31')
,EOMONTH([SampleDate])) AS FirstSunday_ofTheNextMonth
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.