Regards, siva, skyme:siva.boggarapu.ef
Create Function Dbo.HowManyDays(@Month Varchar(15)) Returns Int As Begin Declare @Date Varchar(50), @Days TinyInt Select @Date = '2011-' + @Month + '-01', @Days = DatePart(Day,DateAdd(Month,1,@Date) -1) Return @Days End
Select Dbo.HowManyDays('June') [Days] Go
Declare @Days TinyInt, @Month Varchar(15) Select @Month = 'May' Select @Days = Dbo.HowManyDays(@Month) ;With Sundays As ( Select 1 [Days] Union All Select [Days] + 1 from Sundays where [Days] <31 ) Select SUM([Day]) [Sundays] from ( select CASE DATENAME(weekday,'2011-' + @Month + '-' + Cast([Days] as varchar)) WHEN 'Sunday' Then 1 Else 0 End as [Day] from Sundays Where [Days] <= @Days ) as X
Declare @Days TinyInt, @Month Varchar(15) Select @Month = 'June' Select @Days = Dbo.HowManyDays(@Month) ;With Sundays As ( Select 1 [Days] Union All Select [Days] + 1 from Sundays where [Days] <31 ) Select [Days] [Sundays] from ( select [Days] from Sundays Where [Days] <= @Days and DATENAME(weekday,'2011-' + @Month + '-' + Cast([Days] as varchar)) = 'Sunday' ) as X
Cheers www.SQLServerbuddy.blogspot.com iLink Multitech Solutions
Login to post response