Thinking outside the box

Patron Saint of Lost Yaks
posts - 203, comments - 734, trackbacks - 4

My Links

Advertisement

News

Archives

Post Categories

Simple function to get beginning or end of month

CREATE FUNCTION dbo.fnIsOnMonthEdge
(
    @theDate DATETIME
)
RETURNS SMALLINT
AS
BEGIN
    RETURN CASE @theDate
                WHEN '99991231' THEN 1
                ELSE DATEDIFF(MONTH, @theDate, DATEADD(DAY, 1, @theDate))
            END +
            CASE @theDate
                WHEN '17530101' THEN -1
                ELSE DATEDIFF(MONTH, @theDate, DATEADD(DAY, -1, @theDate))
            END
END

 

Print | posted on Thursday, April 14, 2011 1:40 PM | Filed Under [ Optimization SQL Server 2008 Algorithms SQL Server 2005 SQL Server 2000 ]

Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET