当前位置: 代码迷 >> Sql Server >> select 只包含文字的 内容。该怎么处理
  详细解决方案

select 只包含文字的 内容。该怎么处理

热度:137   发布时间:2016-04-27 19:14:37.0
select 只包含文字的 内容。
ID 可以是汉字、数字、字母,也可以是 标点符号。。那么怎么查询ID 只包含汉字,而没有 数字、字母、标点符号的呢。,
SQL code
select * from tb_name where ID not like '%[a-zA-Z0-9]%'     //标点怎么判断呢??


------解决方案--------------------
PATINDEX('%[吖-做]%',@s)>0
------解决方案--------------------
SQL code
select * from tb_name where patindex('%[^a-zA-Z0-9]%')=0
------解决方案--------------------
SQL code
-- 建函数AOKMOKMcreate function AOKMOKM(@y varchar(50))returns char(1)asbegin  declare @i int, @j int  select @i=1, @j=len(@y)  while(@i<[email protected])  begin    if patindex('[吖-做]',substring(@y,@i,1))=0      return 'N'    select @[email protected]+1    end  return 'Y'end----- 测试 ------- 只包含汉字,而没有 数字、字母、标点符号select dbo.AOKMOKM('迪卡') 'r'r----Y-- 只包含汉字数字,而没有字母、标点符号select dbo.AOKMOKM('迪6卡') 'r'r----N-- 只包含汉字数字字母,而没有标点符号select dbo.AOKMOKM('d迪6卡') 'r'r----N-- 只包含汉字标点符号,而没有数字字母select dbo.AOKMOKM('迪,卡') 'r'r----N-- 只包含汉字,而没有数字字母标点符号select dbo.AOKMOKM('唐诗三百首') 'r'r----Y
  相关解决方案