CREATE FUNCTION [dbo].[GetMonthDays](@YY CHAR(4), @MM CHAR(8))
RETURNS INT
AS
BEGIN
DECLARE @Riqi DATETIME,@I INT
if @MM<12
begin
SET @MM=CONVERT(CHAR(5),CONVERT(INT,@MM)+1)
SET @Riqi = dateadd(day,-1,CONVERT(DATETIME,@YY+'-'+@MM+'-01'))
SET @I =CAST(datepart(day,@Riqi) AS INT)
end
else
SET @I =31
return @I
END