CREATEFUNCTIONf_Convert (@ strNVARCHAR (4000), -- string to be converted @ flagbit -- Conversion flag, 0 to halfwidth, 1 to fullwidth) RETURNSnvarchar (4000) ASBEGINDECLARE @ patnvarchar (8 ), @ stepint, @ iint, @ spcintIF @ flag0SELECT @ patN, @ step-
Create function f_Convert (@ str NVARCHAR (4000), -- string to be converted @ flag bit -- Conversion flag, 0 to halfwidth, 1 to fullwidth) RETURNS nvarchar (4000) as begin declare @ pat nvarchar (8), @ step int, @ I int, @ spc int IF @ flag = 0 SELECT @ pat = N, @ step =-
Create function f_Convert (@ str NVARCHAR (4000), -- string to be converted @ flag bit -- Conversion flag, 0 to halfwidth, 1 to fullwidth) 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 -- table1 is the table to be converted. The U.S. server, the Hong Kong Vm, and column1 are the table fields to be converted.
Call: update table1 set column1 = dbo. f_Convert (column1, 0);, Hong Kong VM