--创建函数(得到字符串中的汉字)
create function [dbo].[m_getchinese]
(
@chinese nvarchar(max)
)
returns varchar(100)
as
begin
while patindex('%[^吖-咗]%',@chinese) > 0
begin
set @chinese = stuff(@chinese,patindex('%[^吖-咗]%',@chinese),1,N'');
end
return @chinese
end
go
--创建函数(得到字符串中的字母)
create function [dbo].[m_getstr](@maco varchar(100))
returns varchar(max)
as
begin
while patindex('%[^a-z]%',@maco) > 0
begin
set @maco=stuff(@maco,patindex('%[^a-z]%',@maco),1,'')
end
return @maco
end
go
--创建函数(得到字符串中的数字)
create function [dbo].[m_getnumber]
(
@mysql_one nvarchar(200)
)
returns varchar(200)
begin
declare @mysql_two varchar(200)
select @mysql_two=
substring(@mysql_one,patindex('%[0-9.]%',@mysql_one),patindex('%[^0-9.]%',substring(@mysql_one,patindex('%[0-9.]%',@mysql_one),
len(@mysql_one)-patindex('%[0-9.]%',@mysql_one)+1))-1)
return @mysql_two;
end
--测试
select dbo.[m_getchinese]('China2009中国HRB4-1v')
select dbo.[m_getstr]('China2009中国HRB4-1v')
select dbo.[m_getnumber]('China2009中国HRB4-1v')
--运行结果
/*
-----------
中国
-----------
ChinaHRBv
-----------
2009
*/
转载来源:http://blog.csdn.net/maco_wang/article/details/6260197