Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
asifbhura
Posting Yak Master
165 Posts |
Posted - 2014-05-21 : 00:00:24
|
Hello,I want to have list of week no. and its startdate and enddate of givenmonth and yearsupposeI have month no: 5(May) and year(2014)i want output like Start Dates End Dates week nos.regards,ASIF |
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2014-05-21 : 01:11:32
|
DECLARE @Month CHAR(10) = '10',@Year CHAR(10) = '2014'DECLARE @SDate DATE,@EDate DATESET @SDate = CONVERT(DATE,@Month + '/01/' + @Year)SET @EDate = DATEADD(MONTH,1,@SDate)SET @EDate = DATEADD(D,-1,@EDate); WITH CTE(WeekId,Date) AS( SELECT DATEPART(Wk,@SDate),@SDate UNION ALL SELECT DATEPART(Wk,DATEADD(D,1,Date)),DATEADD(D,1,Date) FROM CTE WHERE Date < @EDate) SELECT WeekId , MIN(Date) AS 'StartDate' , MAX(Date) AS 'EndDate'FROM CTEGROUP BY WeekIdVeera |
|
|
|
|
|
|
|