SQL character numbers convert letters

Source: Internet
Author: User

1, the number of characters to convert to Chinese capital,

Attention

100==> 100 rather than ==> 100

123==> 123 rather than ==> 123

CREATE FUNCTIONFn_numberconvertchinase (@number NVARCHAR( -))RETURNS NVARCHAR( -) asBEGINDECLARE @res NVARCHAR( -)DECLARE @char CHAR(1)SET @res = "'SET @char = substring(@number,1,1)SELECT @res =( Case @char     when '1'  Then 'a'     when '2'  Then 'two'     when '3'  Then 'three'     when '4'  Then 'Four'     when '5'  Then 'Five'     when '6'  Then 'Six'     when '7'  Then 'Seven'     when '8'  Then 'Eight'     when '9'  Then 'Nine'     when '0'  Then '0'    ELSE substring(@number,1,1)END )IF(Len(@number)> 1)BEGIN    SET @res =  @res +Dbo.fn_numberconvertchinase (substring(@number,2,Len(@number)-1))ENDRETURN @res END

2. Get the first letter of the character and turn it into uppercase

CREATE FUNCTIONFn_getpy (@str NVARCHAR(4000))RETURNS NVARCHAR(4000) asBEGIN    DECLARE @strlen INT; DECLARE @re NVARCHAR(4000); --Digit to uppercase in character    SELECT @str=Dbo.fn_numberconvertchinase (@str); DECLARE @t Table(CHRnchar(1) Collate Chinese_prc_ci_as,letternchar(1))    INSERT  into @t(Chr,letter)SELECT 'Acridine','A' UNION  All SELECT 'Eight','B' UNION  All      SELECT 'Cha','C' UNION  All SELECT 'Otah','D' UNION  All      SELECT 'Ehegan','E' UNION  All SELECT 'Hair','F' UNION  All      SELECT 'Xu','G' UNION  All SELECT 'hafnium','H' UNION  All      SELECT ' not','J' UNION  All SELECT 'ka','K' UNION  All      SELECT ' Garbage','L' UNION  All SELECT '嘸','M' UNION  All      SELECT 'Hallasan','N' UNION  All SELECT 'Oh','O' UNION  All      SELECT '妑','P' UNION  All SELECT 'Seven','Q' UNION  All      SELECT '呥','R' UNION  All SELECT 'SA','S' UNION  All      SELECT 'his','T' UNION  All SELECT '屲','W' UNION  All      SELECT 'XI','X' UNION  All SELECT 'ya','Y' UNION  All      SELECT 'as','Z'; SELECT @strlen=Len(@str),@re="';  while @strlen>0      BEGIN        SELECT TOP 1 @re=Letter+@re,@strlen=@strlen-1           from @tAWHEREChr<=substring(@str,@strlen,1)          ORDER  byChrDESC        IF @ @rowcount=0          SELECT @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1      END  RETURN(UPPER(@re))END

SQL character numbers convert letters

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.