SQL Server 中查询非中文,非英文,非数字的特殊列

今天在处理一个用户名数据库时,发现有些不正常的数据存在,按照逻辑,用户名只能是数字,字母,下划线和纯中文这样的字符组合存在,不应该有其他组合存在,但是发现数据库中由于各种历史原因,有些不正常的存在,如何找到这些异常数据,在CSDN的 SQL Server 版问了这样两个问题,如下:

http://topic.csdn.net/u/20100111/14/529a21a1-3ea8-4263-a0d9-34e83be79b1d.html

http://topic.csdn.net/u/20100111/15/c2a124c5-bc5b-4626-86ce-c5b862cf5cff.html

感谢CSDN的网友帮忙解决了这个问题,下面就是解决方法的汇总:

if object_id('[t1]') is not null 
	drop table [t1]
create table [t1]([c] nvarchar(20))

insert [t1]
select 'aaa' union all		-- 此数据不应该被搜索到
select 'bcds' union all		-- 此数据不应该被搜索到
select 'a1' union all		-- 此数据不应该被搜索到
select '' union all		-- 此数据不应该被搜索到
select '^%' union all		-- 应该搜索到
select 'ew1' union all		-- 此数据不应该被搜索到
select '344' union all		-- 此数据不应该被搜索到
select '__' union all		-- 此数据不应该被搜索到
select '213_21' union all	-- 此数据不应该被搜索到	
select 'a_2' union all		-- 此数据不应该被搜索到
select 'd' union all		-- 此数据不应该被搜索到
select 'ddd' union all		-- 此数据不应该被搜索到
select '电风扇' union all	-- 此数据不应该被搜索到
select '★思寒★' union all	-- 应该搜索到
select 'Ω' union all	        -- 应该搜索到
select 'トントン' union all	-- 应该搜索到
select '***' union all	        -- 应该搜索到
select '///' union all	-- 应该搜索到
select '@-@' union all	        -- 应该搜索到
select '@小慧' union all	        -- 应该搜索到
select '~*晓菊*~' union all	-- 应该搜索到
select '啊★洛' union all	-- 应该搜索到
select '不思議の夜' union all	-- 应该搜索到
select '(嘉宾)胡飞' union all	-- 应该搜索到
select '--------------'		-- 应该搜索到



select * from [t1] WHERE PATINDEX('%[0-9a-z_]%',c)=0 
and PATINDEX('%[^吖-座]%',c) <> 0

 

另外感慨一下,CSDN的 SQL Server 版 问出问题到解决问题,竟然比Google 搜索答案还要快, SQL Server 版 的牛人真多, 而且回答的这么快,实在让人吃惊。

  • 0
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值