Sunday, 26 March 2017

Find the Leap year

With the help of below sql script we can find the year is leap year or not.
DECLARE @year AS INT
SET @year=2016
DECLARE @Result As int
set @Result= (
select 365+
case
when @year%400=0 then 1
when @year%100=0 then 0
when @year%4=0 then 1
else 0
end)
select case when @Result=366 then 'Leap year'
else 'Not Leap Year' End as 'Result'
See the result
  

I am changing the year. Taking 2017. See the result.
  

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts