-------Display all Days in a month Function
CREATE FUNCTION UDF_ShowAllDaysInMonth (@SDate DATETIME)
RETURNS @DAYS TABLE ([DAYS] DATETIME )
AS
BEGIN
DECLARE @I INT
DECLARE @CN INT
SELECT @CN= DATEPART(DD,DATEADD(DD,-1, DATEADD(MM,DATEDIFF(MM,0,@SDate)+1,0)))
SET @I=0
WHILE (@I<@CN)
BEGIN
INSERT INTO @DAYS SELECT DATEADD(DD,@I,@SDate)
SET @I=@I+1
END
RETURN
END
SELECT * FROM UDF_ShowAllDaysInMonth('2011-02-01')
No comments:
Post a Comment