SQL Server database full-angle conversion to half-width _mssql

Source: Internet
Author: User
Copy Code code as follows:

CREATE FUNCTION F_convert (
@str NVARCHAR (4000),--the string to convert
@flag bit--conversion flag, 0 converted to half angle, 1 convert 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 (@str, n ', n ')
ELSE
SELECT @pat =n '%[!-~]% ', @step = 65248,
@str =replace (@str, n ', n ')
SET @i=patindex (@pat COLLATE latin1_general_bin, @str)
While @i> 0
SELECT @str =replace (@str,
SUBSTRING (@str, @i,1),
NCHAR (UNICODE (SUBSTRING (@str, @i,1)) + @step)
, @i=patindex (@pat COLLATE latin1_general_bin, @str)
Return (@str)
End
Go call: Update table1 set Column1=dbo.f_convert (column1,0);
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.