Monday, May 16, 2016

How to find a Leap year by using User Defined functions

Leap year by using User Defined functions



Function:


CREATE  FUNCTION [dbo].[LeapYear] ( @Date    DATETIME )
RETURNS VARCHAR(100)
AS
BEGIN

    IF (YEAR( @Date ) % 4 = 0 AND YEAR( @Date ) % 100 != 0) OR
        YEAR( @Date ) % 400 = 0

        RETURN 'Leap Year'

    RETURN 'Non-Leap Year'

END
GO

To execute the above function 

select [dbo].[LeapYear] ('2016')


Once you practice delete all these stuff 


 drop function [dbo].[LeapYear]


No comments:

Post a Comment