create FUNCTION f_GetMonthDay
(
@year int,
@month int
)
RETURNS int
AS
BEGIN
Declare @Ret_V int
Declare @tmpDate datetime
if @month>12
begin
set @year=@year+1
set @month=@month-12
end
SET @tmpDate = Convert(datetime, Cast(@year as varchar(4)) + '-' + Cast(@month as varchar(2)) + '-01')
SET @Ret_V = DateDiff(dd,@tmpDate,DateAdd(mm,1,@tmpDate))
RETURN @Ret_V
END
--使用方法(月份超过12后,会自动修改年份,得到相应的天数)
select dbo.f_GetMonthDay(2009,17)