sql 根据字母获取以字母开头的数据
2011-07-25 16:21
357 查看
函数1:
ALTER Function [dbo].[Get_Str](@Str VARCHAR(100))
Returns VARCHAR(100)
as
BEGIN
WHILE PATINDEX('%[^a-z]%',@Str) > 0
BEGIN
set @Str=stuff(@Str,patindex('%[^a-z]%',@Str),1,'')
END
RETURN @Str
END
函数2:
ALTER function [dbo].[fun_getPY](@str nvarchar(4000))
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--如果非汉字字符,返回原字符
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (select top 1 PY from (
select 'A' as PY,N'驁' as word
union all select 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鰒'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'漚'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'籜'
union all select 'W',N'鶩'
union all select 'X',N'鑂'
union all select 'Y',N'韻'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC) else @word end)
set @str=right(@str,len(@str)-1)
end
return DBO.Get_Str(@PY)
end
以上为数据库函数 提取英文过滤数字,和获取获取汉字首字母
调用方法为:
SELECT OrgName FROM
Organization_OrgInfo WHERE fun_getPY(OrgName) LIKE 'f%'
ALTER Function [dbo].[Get_Str](@Str VARCHAR(100))
Returns VARCHAR(100)
as
BEGIN
WHILE PATINDEX('%[^a-z]%',@Str) > 0
BEGIN
set @Str=stuff(@Str,patindex('%[^a-z]%',@Str),1,'')
END
RETURN @Str
END
函数2:
ALTER function [dbo].[fun_getPY](@str nvarchar(4000))
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--如果非汉字字符,返回原字符
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (select top 1 PY from (
select 'A' as PY,N'驁' as word
union all select 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鰒'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'漚'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'籜'
union all select 'W',N'鶩'
union all select 'X',N'鑂'
union all select 'Y',N'韻'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC) else @word end)
set @str=right(@str,len(@str)-1)
end
return DBO.Get_Str(@PY)
end
以上为数据库函数 提取英文过滤数字,和获取获取汉字首字母
调用方法为:
SELECT OrgName FROM
Organization_OrgInfo WHERE fun_getPY(OrgName) LIKE 'f%'
相关文章推荐
- 根据时间获取最新数据 SQL(每一个人或者每一项)
- sql 根据时间获取数据
- sql 根据指定条件获取一个字段批量获取数据插入另外一张表字段中+MD5加密
- 根据已有的表创建新的表和从另外的表获取数据到新的表里面方法sql
- SqlServer 中根据概率获取数据的sql 写法—抄袭的记录下
- 一个关于SqlServer 中根据概率获取数据的sql 写法
- 根据当前字母获取下一位 java
- Oracle 删除重复数据只留一条 查询及删除重复记录的SQL语句 1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断 select * from 表 wher
- oracle中根据时间获取最新的一条数据
- 本地动态SQL(Open for等)如何获取SQL的定义属性,包括栏位名称和数据类型
- 根据BITMAPINFO获取位图数据
- 20150303--从SQL中获取数据的三级联动
- Sql 获取指定库,根据表查询表,根据表查询字段
- 获取SQLServer 的最完整数据字典的SQL 语句
- Map排序,获取map的第一值,根据value取key等操作(数据预处理)
- SQL获取重复数据
- 根据图片网络地址获取图片的byte[]类型数据
- 根据父级编号获取无限树结构数据表中所有子节点的数据
- 根据参数远程获取不同的数据