SQL conversion full-width and half-width functions

Source: Internet
Author: User

SQL Conversion full-width and half-width functions
CREATE   FUNCTIONF_convert (@str   NVARCHAR(4000),--the string to convert    @flag   bit                             --conversion flag, 0 converted to half angle, 1 conversion to perfect angle)RETURNS   nvarchar(4000)  as BEGIN     DECLARE   @pat   nvarchar(8),@step   int,@i   int,@spc   int     IF   @flag=0         SELECT   @pat=N'%[! -~]%',@step=-65248,         @str=REPLACE(@strN'    'N'   ')     ELSE         SELECT   @pat=N'%[!-~]%',@step=65248,         @str=REPLACE(@strN'   'N'    ')     SET   @i=PATINDEX(@patCOLLATE Latin1_General_BIN,@str)      while   @i> 0         SELECT   @str=REPLACE(@str,         SUBSTRING(@str,@i,1),         NCHAR(UNICODE(SUBSTRING(@str,@i,1))+@step))         ,@i=PATINDEX(@patCOLLATE Latin1_General_BIN,@str)     RETURN(@str) END GOCall:UpdateTable1SetColumn1=Dbo.f_convert (Column1,0); Declare @s1 varchar(8000)  Select   @s1='Zhong 2-3456a78stuvabn China opwxyz' SelectDbo.f_convert (@s1,0), Dbo.f_convert (@s1,1)

   

SQL conversion full-width and half-width functions

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.