Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 function error

Author  Topic 

sushma patle
Starting Member

15 Posts

Posted - 2008-05-21 : 03:32:26
what is the error in that function, please help to find out

create function [dbo].[ufn_IsLeapYear] ( @pDate DATETIME) returns bit
as
begin
declare @b bit


if (YEAR(@pDate)%4=0 ) AND YEAR(@pDate)%100 != 0))
set @b = 1
else if (YEAR(@pDate) % 400 = 0)
set @b= 0
Return(@b)
end


spatle

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-21 : 03:42:54
Year 2000 IS leap year even if it is divisable by 100.
CREATE FUNCTION	dbo.ufn_IsLeapYear
(
@pDate DATETIME
)
RETURNS BIT
AS
BEGIN
DECLARE @b BIT

SET @b = CASE
WHEN YEAR(@pDate) % 400 = 0 THEN 1
WHEN YEAR(@pDate) % 100 = 0 THEN 0
WHEN YEAR(@pDate) % 4 = 0 THEN 1
ELSE 0
END

RETURN @b
END



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -