用户需要传入年份,获取该年份2月份的天数。可以写成一个用户自定义函数。
View Code
CREATE FUNCTION [dbo].[DaysOfFebruary]
(
@Year INT
)
RETURNS INT
AS
BEGIN
RETURN CASE WHEN (@Year % 4 = 0 AND @Year % 100 <> 0) OR (@Year % 400 = 0) THEN 29 ELSE 28 END
END
(
@Year INT
)
RETURNS INT
AS
BEGIN
RETURN CASE WHEN (@Year % 4 = 0 AND @Year % 100 <> 0) OR (@Year % 400 = 0) THEN 29 ELSE 28 END
END
代码演示:
SELECT [dbo].[DaysOfFebruary](2011)
执行结果: