--full2half
CREATE FUNCTION [dbo].[full2half](
@String nvarchar(max)
)
RETURNS nvarchar(max)
AS
/*
全角(Fullwidth)转换为半角(Halfwidth)
*/
BEGIN
DECLARE @chr nchar(1)
DECLARE @i int
SET @String = REPLACE(@String,N' ',N' ')
SET @i = PATINDEX(N'%[!-~]%' COLLATE Latin1_General_BIN,@String)
WHILE @i > 0
BEGIN
SET @chr = SUBSTRING(@String,@i,1)
SET @String = REPLACE(@String,@chr,NCHAR(UNICODE(@chr)-65248))
SET @i = PATINDEX(N'%[!-~]%' COLLATE Latin1_General_BIN,@String)
END
RETURN @String
END
GO
CREATE FUNCTION [dbo].[half2full](
@String nvarchar(max)
)
RETURNS nvarchar(max)
AS
/*
半角(Halfwidth)转换为全角(Fullwidth)
*/
BEGIN
DECLARE @chr nchar(1)
DECLARE @i int
SET @String = REPLACE(@String,N' ',N' ')
SET @i = PATINDEX(N'%[!-~]%' COLLATE Latin1_General_BIN,@String)
WHILE @i > 0
BEGIN
SET @chr = SUBSTRING(@String,@i,1)
SET @String = REPLACE(@String,@chr,NCHAR(UNICODE(@chr)+65248))
SET @i = PATINDEX(N'%[!-~]%' COLLATE Latin1_General_BIN,@String)
END
RETURN @String
END
GO