//Date List Month Wise
//StartDate Input and EndDate Input
DECLARE @Date DATE='03/15/2016'
DECLARE @startDate DATE=CAST(MONTH(@Date) AS VARCHAR) + '/' + '01/' + + CAST(YEAR(@Date) AS VARCHAR) -- mm/dd/yyyy
DECLARE @endDate DATE=DATEADD(DAY,-1,DATEADD(MONTH,1,@startDate))
SELECT [Date] = DATEADD(Day,Number,@startDate)
FROM master..spt_values
WHERE Type='P'
AND DATEADD(day,Number,@startDate) <= @endDate
=====================================================================
O/P:=
Date
2016-03-01
2016-03-02
2016-03-03
2016-03-04
2016-03-05
2016-03-06
2016-03-07
2016-03-08
2016-03-09
2016-03-10
2016-03-11
2016-03-12
2016-03-13
2016-03-14
2016-03-15
2016-03-16
2016-03-17
2016-03-18
2016-03-19
2016-03-20
2016-03-21
2016-03-22
2016-03-23
2016-03-24
2016-03-25
2016-03-26
2016-03-27
2016-03-28
2016-03-29
2016-03-30
2016-03-31
//StartDate Input and EndDate Input
DECLARE @Date DATE='03/15/2016'
DECLARE @startDate DATE=CAST(MONTH(@Date) AS VARCHAR) + '/' + '01/' + + CAST(YEAR(@Date) AS VARCHAR) -- mm/dd/yyyy
DECLARE @endDate DATE=DATEADD(DAY,-1,DATEADD(MONTH,1,@startDate))
SELECT [Date] = DATEADD(Day,Number,@startDate)
FROM master..spt_values
WHERE Type='P'
AND DATEADD(day,Number,@startDate) <= @endDate
=====================================================================
O/P:=
Date
2016-03-01
2016-03-02
2016-03-03
2016-03-04
2016-03-05
2016-03-06
2016-03-07
2016-03-08
2016-03-09
2016-03-10
2016-03-11
2016-03-12
2016-03-13
2016-03-14
2016-03-15
2016-03-16
2016-03-17
2016-03-18
2016-03-19
2016-03-20
2016-03-21
2016-03-22
2016-03-23
2016-03-24
2016-03-25
2016-03-26
2016-03-27
2016-03-28
2016-03-29
2016-03-30
2016-03-31
No comments:
Post a Comment