i want to create storeprocedure that return specific days of the period ,as parameter i am passing periods(from and to date) and day of the week ,and specific day.
example :
for the period 1-june-2013 to 30-june-2013 i need to get all sundays when i passed sunday as parameter


Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Oct 30, 2013, 3:55 AM EDT
Try this SP,
CREATE PROCEDURE getDaysBetweenTwoDate
(
@FromDate DATETIME,
@ToDate DATETIME,
@dayOfWeek int -- should be 1 to 7 [sunday - satuday]
)
AS
BEGIN
DECLARE @TOTALCount INT
SET @FromDate = DATEADD(DAY,-1,@FromDate)
Select @TOTALCount= DATEDIFF(DD,@FromDate,@ToDate);
WITH d AS
(
SELECT top (@TOTALCount) AllDays = DATEADD(DAY, ROW_NUMBER()
OVER (ORDER BY object_id), REPLACE(@FromDate,'-',''))
FROM sys.all_objects
)
SELECT alldays, datepart(dw, alldays) From d where datepart(dw, alldays) = @dayOfWeek
RETURN
END
GO
Exec getAllDaysBetweenTwoDate '06-01-2013','30-06-2014' ,1
mohammed shamsheerRank #4,152 · 361 reputationPosted Oct 30, 2013, 4:05 AM EDT
mohammed shamsheerRank #4,152 · 361 reputationPosted Oct 30, 2013, 4:41 AM EDT
mohammed shamsheerRank #4,152 · 361 reputationPosted Oct 30, 2013, 4:52 AM EDT