I have changed like below and also modified logic required to find sunday's by using datepart
function. If you want to return saturday's count also then add it in where clause.
create function [dbo].[getSundaysandSaturdays]
(
@Year int,
@Month int
)
RETURNS int
as
begin
declare @fdays int
;with dates as
(
select dateadd(month,@month-1,dateadd(year,@year-1900,0)) as StartDate
union all
select startdate + 1 from dates where month(startdate+1) = @Month
)
select @fdays=count(*) from dates where datepart(dw,StartDate) =1
return @fdays
end
And Call function like below
select dbo.[getSundaysandSaturdays](2015,11)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…