时间:2021-07-01 10:21:17 帮助过:54人阅读
CREATE FUNCTION dbo.Fun_YiYueDeZuiHouYiTian
(
@BenYue CHAR(6)
)
RETURNS CHAR(10)
AS
BEGIN
DECLARE @ReturnValue CHAR(2)
DECLARE @YueFen CHAR(2)
DECLARE @NianFen CHAR(4)
SET @YueFen = RIGHT(@BenYue, 2)
SET @NianFen = LEFT(@BenYue, 4)
IF @YueFen IN ('01', '03', '05', '07', '08', '10', '12')
BEGIN
SET @ReturnValue = '31'
END
IF @YueFen IN ('04', '06', '09', '11')
BEGIN
SET @ReturnValue = '30'
END
IF @YueFen = '02'
BEGIN
IF ((@NianFen % 4 = 0 AND @NianFen % 100 <> 0) OR (@NianFen % 400 = 0))
BEGIN
SET @ReturnValue = '29'
END
ELSE
BEGIN
SET @ReturnValue = '28'
END
END
RETURN @NianFen + '-' + @YueFen + '-' + @ReturnValue
END