Hi Friend
I have a Sp and it have two parameter's (@month,@year,@day). I want to insert month ,year and day such as mon ,tue ,sun ,sat,than print the Number of day in particular month. ------------
execute: --------
exec datee 12 2008 sun
output is: __________
sunady : 5
|
| Author: Tejinder Singh Barnala 24 Dec 2008 | Member Level: Gold | Rating:  Points: 4 |
try it........
create proc getweeekdayinmonth(@year int, @month int, @day varchar(3)) as
declare @date as datetime declare @loopcounter as int set @loopcounter = 0 set @date = (select cast(@year as varchar) + '/' + cast(@month as varchar) + '/' + '01') while @month = month(@date) begin if(substring(datename(dw,@date),1, 3) = @day) begin set @loopcounter = @loopcounter + 1 end set @date = dateadd(dd,1,@date) end select @year as [year], @month as [month], @day as [day], @loopcounter as counter
go
exec getweeekdayinmonth 2008,12,'sun' /*enter first three digit of weekday name*/
Many Thanks Tejinder Singh Barnala /*I have the simplest tastes. I am always satisfied with the best*/
|
| Author: Santhosh Aravind 24 Dec 2008 | Member Level: Gold | Rating:  Points: 3 |
declare @month int,@year int, @day varchar(10), @NoOfDays int declare @d1 datetime
set @day = 'sun' set @year = 2008 set @month = 12
SET @NoOfDays = 0
set @d1 = cast(cast(@year as varchar) + '/' + cast(@month as varchar) + '/01' as datetime)
while @month = month(@d1) begin if(SUBSTRING(DATENAME(dw,@d1),1, 3) = @day) set @NoOfDays = @NoOfDays + 1
set @d1 = DATEADD(dd,1,@d1) end
SELECT @NoOfDays
|