SQL query to display all Sundays in the current month.
In this article, I am going to explain how to display all Sundays of the current month. In my last post, I have discussed how to display whole dates of the current month. Now we will see how to display all Sundays of the current month.
Hi Friends,
I have changed only few line of the last posted query of mine. First, I will display all the dates of the current month with days ie, date name
then I used that names in "where" condition.
Please go through it and say your valuable comment through mail or here.
WITH CTE AS
(
SELECT DATEADD(D,-DATEPART(D,GETDATE())+1,GETDATE())[FIRST SUNDAY DATE],DATENAME(DW,DATEADD(D,-DATEPART(D,GETDATE())+1,GETDATE()))[DAY NAME]
UNION ALL
SELECT DATEADD(D,1,[FIRST SUNDAY DATE]),DATENAME(DW,DATEADD(D,1,[FIRST SUNDAY DATE]))FROM CTE WHERE [FIRST SUNDAY DATE]<=DATEADD(D,-DATEPART(D,GETDATE()),DATEADD(M,1,GETDATE()))-1
)
SELECT *FROM CTE WHERE [DAY NAME]='SUNDAY'
Thank you For Reading this article.Dont Forget to say your comments here.
Thank you.
Note:
I hope this will be useful to all. If you have queries please contact the below mail address:
rathin59117@gmail.com
Reference: Rathin813.blogspot.com
This is good.