Calculates the User-Defined Function of the last day of a specified year.

Source: Internet
Author: User

/*

Name: fun_yiyuedezuihouyitian

Function: Calculate the last day of the month based on the input format, such as "200311 ".

Parameters:

Benyue this month

Type: Char (6)

Format: 200311"

Returnvalue:

The format is "200310 ".

Type: Char (6)

Steps:

Author: waxdoll Cheung

Date: 2004-04-04

*/

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.