如何判断一个字段为纯字母?

clinfo 2006-10-01 11:38:12
如何判断一个字段为纯字母?就是我要过滤出这个字段全为字母的一些数据。

尝试用了:

select charindex(DnName+'|','a|b|c|d|e|f|g|h|i|t|d|-|')> 0

不行

请教。。。
...全文
487 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
liumang9527 2006-10-02
  • 打赏
  • 举报
回复
楼上高
hellowork 2006-10-02
  • 打赏
  • 举报
回复
----创建测试数据
declare @t table(id int identity(1,1),DnName varchar(50))
insert @t(DnName)
select 'a|b|c|d|e|f|g|h|i|t|d|-|' union all
select 'a123,xyz' union all
select 'abcDeFgh' union all
select 'a-()*v'

----查询纯字符的行
select * from @t where patindex('%[^a-z]%',DnName) = 0

/*结果
id DnName
--------------------------------
3 abcDeFgh
*/
liumang9527 2006-10-02
  • 打赏
  • 举报
回复
select unicode('A')--65
select unicode('Z')--90
select unicode('a')--97
select unicode('z')--122

如果你要判断的字符串在上面的范围内,那么对每一个字符判断它的Unicode值是否在范围之内。
clinfo 2006-10-02
  • 打赏
  • 举报
回复
patindex('%[^a-z]%',DnName) = 0

一句搞定。感谢。给分

34,589

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧