-- select dbo.F_MonthCount('2012-02-03')
-- =============================================
ALTER FUNCTION [dbo].[F_MonthCount]
(
@date datetime
)
RETURNS int
AS
BEGIN
DECLARE @start datetime,@count int
select @start=cast(year(@date) as varchar(4))+'-'+cast(Month(@date) as varchar(2))+'-'+'01'
SELECT @count=datediff(day,@start,DATEADD(dd, -DAY(DATEADD(m,1,@date)), DATEADD(m,1,@date)))+1
RETURN @count
END
No comments:
Post a Comment