22,209
社区成员
发帖
与我相关
我的任务
分享
select * from tb where patindex('%[吖-做]%',name)>0
错,如果有中文和英文、数字,还是会统计出来的。
If not object_id('[tb]') is null
Drop table [tb]
Go
Create table [tb]([name] nvarchar(8))
Insert tb
Select 'aaa' union all
Select '张三11' union all
Select 'bbb' union all
Select '李四aa'
Go
--Select * from tb
-->SQL查询如下:
select * from tb where name like '%[吖-做]%'
/*
name
--------
张三11
李四aa
(2 行受影响)
*/
select *
from tb
where PATINDEX('%[a-z]%',name)=0
/*name
--------------------
张三
李四
(2 行受影响)
*/
-- =========================================
-- -----------t_mac 小编-------------
---希望有天成为大虾----
-- =========================================
IF OBJECT_ID('tb') IS NOT NULL
DROP TABLE tb
GO
CREATE TABLE tb(name varchar(20))
go
insert tb SELECT
'aaa' UNION ALL SELECT
'张三' UNION ALL SELECT
'bbb' UNION ALL SELECT
'李四'
go
select *
from tb
where name not like'%[a-z]%'
go
/*------------
(4 行受影响)
name
--------------------
张三
李四
-------*/
---------------------------------
-- Author: htl258(Tony)
-- Date : 2009-07-30 20:33:09
---------------------------------
--> 生成测试数据表:tb
If not object_id('[tb]') is null
Drop table [tb]
Go
Create table [tb]([name] nvarchar(3))
Insert tb
Select 'aaa' union all
Select '张三' union all
Select 'bbb' union all
Select '李四'
Go
--Select * from tb
-->SQL查询如下:
select * from tb where name like '%[吖-做]%'
/*
name
----
张三
李四
(2 行受影响)
*/
select * from tb where patindex('%[吖-做]%',name)>0
/*
name
----
张三
李四
(2 行受影响)
*/
select * from tb where name like '%[吖-做]%'
select *
from tb
where patindex('%[1-9]%',name)<0