SQL Server中全半角转换函数
2011-08-12 13:01
204 查看
CREATE FUNCTION F_Convert_CharSet(
@string nvarchar(4000) -- 输入的字符串
,@flag tinyint -- 转换标识(1:全角转半角;其他:半角转全角)
)
RETURNS nvarchar(2000)
WITH ENCRYPTION
AS
BEGIN
DECLARE @i int
,@ret nvarchar(2000)
select @i=1
SET @ret= ' '
if(@flag=1)
begin
while SUBSTRING(@string,@i,1) <> ' '
begin
if UNICODE(SUBSTRING(@string,@i,1))> 255
SET @ret=@ret+NCHAR(UNICODE(SUBSTRING(@string,@i,1))-
CASE
WHEN SUBSTRING(@string,@i,1)= '。 ' THEN 12244 ELSE 65248
END )
else
SET @ret=@ret+(SUBSTRING(@string,@i,1))
SET @i=@i+1
end
end
else
begin
while @i <=len(@string)
begin
if unicode(SUBSTRING(@string, @i, 1)) <256
select @ret = @ret + NCHAR(unicode(SUBSTRING(@string, @i, 1))+ 0xFEE0 )
else
select @ret = @ret + SUBSTRING(@string, @i, 1)
SET @i=@i+1
end
end
return @ret
end
@string nvarchar(4000) -- 输入的字符串
,@flag tinyint -- 转换标识(1:全角转半角;其他:半角转全角)
)
RETURNS nvarchar(2000)
WITH ENCRYPTION
AS
BEGIN
DECLARE @i int
,@ret nvarchar(2000)
select @i=1
SET @ret= ' '
if(@flag=1)
begin
while SUBSTRING(@string,@i,1) <> ' '
begin
if UNICODE(SUBSTRING(@string,@i,1))> 255
SET @ret=@ret+NCHAR(UNICODE(SUBSTRING(@string,@i,1))-
CASE
WHEN SUBSTRING(@string,@i,1)= '。 ' THEN 12244 ELSE 65248
END )
else
SET @ret=@ret+(SUBSTRING(@string,@i,1))
SET @i=@i+1
end
end
else
begin
while @i <=len(@string)
begin
if unicode(SUBSTRING(@string, @i, 1)) <256
select @ret = @ret + NCHAR(unicode(SUBSTRING(@string, @i, 1))+ 0xFEE0 )
else
select @ret = @ret + SUBSTRING(@string, @i, 1)
SET @i=@i+1
end
end
return @ret
end
相关文章推荐
- oracle 全角半角转换函数.
- SQL Server中全角和半角字符的比较问题
- 全半角转换函数
- Sql Server数据类型转换函数
- oracle 全角半角转换函数
- java 全角半角转换函数
- C#全角半角转换函数
- oracle 全角半角转换函数
- oracle 全角半角转换函数.
- java 全角半角转换函数
- 全角半角转换函数 收集&汇总
- SQL SERVER 数据库储存的值里面前后有空格,有可能是全角或者半角空格,如何在查询中处理
- PHP全角半角转换函数
- SQL Server(第二章) 字符串函数、日期时间函数、转换函数
- 全角和半角互相转换函数
- DB2中一个全角到半角的转换函数
- Sql Server数据类型转换函数
- 全角半角转换函数
- [MSSQL]角半角转换函数
- SQL Server中全角和半角字符的比较问题