SQL Server Month Day turn Chinese character capitalization

Source: Internet
Author: User

Also today in the SQL group asked, it seems that the problem is very simple, but I do not know how to achieve the specific. Baidu has a, to find a master contribution to the answer, remember.

convert Chinese dates in reference link sql

------with related functions------Create  functionConvertnumtochinese (@instr varchar(2))returns varchar(2) asbeginDeclare  @temStr varchar(2)if @instr = '1' Set @temStr =  'a'if @instr ='2'  Set @temStr =  'two'if @instr ='3'  Set @temStr =  'three'if @instr ='4'  Set @temStr =  'Four'if @instr ='5'  Set @temStr =  'Five'if @instr ='6'  Set @temStr =  'Six'if @instr ='7'  Set @temStr =  'Seven'if @instr ='8'  Set @temStr =  'Eight'if @instr ='9'  Set @temStr =  'Nine'if @instr ='0'  Set @temStr =  '0'return @temstrEnd --------------Implementation Key-stored procedure--------------------Create procedureConvertdatetochinese@vdate datetime,@ChineseDateStr varchar( -) out asDeclare @vYear varchar( -)Declare @vMonth varchar( -)Declare @vDay varchar( -)Declare @temstr varchar( -) Set @temstr = "'Set @vYear = Datename(yyyy,@vdate)--Print @vyearSet @vMonth = Datename(MM,@vdate)--Print @vMonthSet @vDay  = Datename(DD,@vdate)--print ' V ' [email protected]--Start calculation YearSet @temstr =Dbo.convertnumtochinese (substring(@vYear,1,1))Set @temstr = @temstr +Dbo.convertnumtochinese (substring(@vYear,2,1))Set @temstr = @temstr +Dbo.convertnumtochinese (substring(@vYear,3,1))Set @temstr = @temstr +Dbo.convertnumtochinese (substring(@vYear,4,1))Set @temstr = @temstr + 'years' --Start Calculation Monthif substring(@vMonth,1,1)= '0'Set @temstr = @temstr +Dbo.convertnumtochinese (substring(@vMonth,2,1))Elsebegin if substring(@vMonth,2,1)= '0'   Set @temstr = @temstr + '10' Else   Set @temstr = @temstr +'10'+Dbo.convertnumtochinese (substring(@vMonth,2,1))End Set @temstr = @temstr + 'Month' --Start Calculation Date if Convert(int,@vDay)< Ten   Set @temstr = @temstr +Dbo.convertnumtochinese (substring(@vDay,1,1))Elsebegin  if substring(@vDay,2,1)= '0'    begin      if  substring(@vDay,1,1)<> '1'       Set  @temstr = @temstr +Dbo.convertnumtochinese (substring(@vDay,1,1))+ '10'      Else        Set @temstr = @temstr +  '10'     End  Else    begin     if substring(@vDay,1,1)<> '1'       Set @temstr = @temstr  +Dbo.convertnumtochinese (substring(@vDay,1,1))+ '10' +Dbo.convertnumtochinese (substring(@vDay,2,1))     Else        Set @temstr = @temstr + '10' +Dbo.convertnumtochinese (substring(@vDay,2,1))    EndEndSet @temstr = @temstr +  'Day'  Print @temstrSet @ChineseDateStr = @temstr
View Code

Call Method:

Declare @str_format varchar (a); exec ' 2017-11-08 13:30 ',@str_format  outputselect@str_format

Results:

SQL Server Month Day turn Chinese character capitalization

Related Article

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.