sql_全半角转换
sql 数字全角半角转换
create FUNCTION dbo.ConvertWordAngle ( @str NVARCHAR(4000), --要转换的字符串 @flag bit --转换标志,0转换成半角,1转换成全角 )RETURNS nvarchar(4000) AS BEGIN DECLARE @pat nvarchar(8),@step int,@i int,@spc int IF @flag=0 begin SELECT @pat=N'%[!-~]%',@step=-65248, @str=REPLACE(@str,N' ',N' ') ; end ELSE begin SELECT @pat=N'%[!-~]%',@step=65248, @str=REPLACE(@str,N' ',N' ') end 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
调用方式: select dbo.ConvertWordAngle('W19691003',0);
本文来自博客园,作者:兴想事成,转载请注明原文链接:https://www.cnblogs.com/mjxxsc/p/7474800.html