
I need to write a function to determine if particular year is a leap year (i.e. February contains 29 days rather than 28 days). I know that there are various rules for calculating leap years. Is there an easy way to figure this out? Can you provide an example or two to validate various years?

create function dbo.fn_IsLeapYear (@year int) returns bit as begin
return(select case datepart(mm, dateadd(dd, 1, cast((cast(@year as varchar(4)) + '0228') as datetime))) when 2 then 1 else 0 end) end
go
select dbo.fn_IsLeapYear(1900) as 'IsLeapYear?'
select dbo.fn_IsLeapYear(2000) as 'IsLeapYear?'
select dbo.fn_IsLeapYear(2007) as 'IsLeapYear?'
select dbo.fn_IsLeapYear(2008) as 'IsLeapYear?'

SQL_Server_2008基础教程11_计算机软件及应用_IT/计算机_专业资料。第11章 ...使用CREATE FUNCTION语句创建用户定义函数第3页 2013年8月6日 本章内容 11.1 ...
SQL Server 2008之CREATE TABLE_计算机软件及应用_IT/计算机_专业资料。CREATE TABLE [ database_name.[ owner ] . owner.] table_name ( { <column_...
使用CREATE FUNCTION语句创建用户定义函数第3页 2013年8月15日 本章内容 11.1...在Microsoft SQL Server 2008系统中,可以使用 Transact-SQL语言编写存储过程,也...
SQL SERVER 2008复习_IT/计算机_专业资料。数据库SQL SERVER 2008复习资料(...(bookid) ■用户自定义函数 创建标量函数 create function 函数名(@参数 数据...
Sql server 2008 的基础知识总结_计算机软件及应用_IT/计算机_专业资料。sql ...自定义函数 --自定义函数 use XJ go create function MoneyBack(@hireDate ...
sql server 2008 存储过程与触发器_IT/计算机_专业资料。sql server 2008 ...CREATE DEFAULT CREATE 或 ALTER FUNCTION CREATE 或 ALTER PROCEDURE SET ...
SQL SERVER 2008命令实例_计算机软件及应用_IT/计算机_专业资料。SQL SERVER 2008命令实例创建数据库语句: create database test1 on primary ( name='test1_...
sql server 2008资源调控器_计算机软件及应用_IT/计算机_专业资料。sql server...USER_READONLY 所使用的 cpu 资源不超过 10% CREATE FUNCTION dbo.rgclassifier...
SQL Server 2005 中也可以通过 SQL 语句来创建表分区,但在 SQL Server 2008 ...(T-SQL: CREATE PARTITION FUNCTION) 创建分区方案以指定分区函数的分区在文件组...
第5章 SQL Server 2008高级应用 数据库系统原理及应用 5.1 Transact-SQL程序... CREATE DEFAULT CREATE SCHEMA CREATE 或 ALTER FUNCTION CREATE 或 ALTER ...
热门文档