select * from tb where col like '%AB_B%'--orselect * from tb where patindex('%AB[A-Z]B%',Col)>0
if object_id('[tb]') is not null drop table [tb] create table [tb]([value] varchar(8)) insert [tb] select 'ABxBAxA' union all select 'BxBABxAA' union all select 'BxBAxAB' union all select 'AxBxBAAx' union all select 'BxABBxA'select * from tb where value like '%AB_B%' /* value -------- ABxBAxA(所影响的行数为 1 行) */select * from tb where patindex('%AB_B%',value)>0/* value -------- ABxBAxA(所影响的行数为 1 行) */
汗 select * from 表 where 字段 like '%[A-Z]B[A-Z]B%'
select * from tb where col like '%AB?B%'两边模糊用 % 单个字符匹配不同数据库系统可能会有些差异,试试上面。有用问号代替的。
--这个满足要求了吧 ---------------------------------------------------------------- -- Author :fredrickhu(小F 向高手学习) -- Date :2009-06-27 16:35:26 ---------------------------------------------------------------- --> 测试数据:[tb] if object_id('[tb]') is not null drop table [tb] create table [tb]([value] varchar(8)) insert [tb] select 'ABxBAxA' union all select 'BxBABxAA' union all select 'BxBAxAB' union all select 'AxBxBAAx' union all select 'BxABBxA' --------------开始查询-------------------------- select * from tb where value like '%[A-Z]B[A-Z]B%' ----------------结果---------------------------- /* value -------- ABxBAxA BxBABxAA AxBxBAAx (所影响的行数为 3 行) */
create table [tb]([value] varchar(8))
insert [tb]
select 'ABxBAxA' union all
select 'BxBABxAA' union all
select 'BxBAxAB' union all
select 'AxBxBAAx' union all
select 'BxABBxA'select * from tb where value like '%AB_B%'
/*
value
--------
ABxBAxA(所影响的行数为 1 行)
*/select * from tb where patindex('%AB_B%',value)>0/*
value
--------
ABxBAxA(所影响的行数为 1 行)
*/
select * from 表 where 字段 like '%[A-Z]B[A-Z]B%'
select * from tb where col like '%AB?B%'两边模糊用 %
单个字符匹配不同数据库系统可能会有些差异,试试上面。有用问号代替的。
我的目标是要实现这样的匹配:
ABxBAxA
BxBABxAA
BxBAxAB
AxBxBAAx
BxABBxA
----------------------------------------------------------------
-- Author :fredrickhu(小F 向高手学习)
-- Date :2009-06-27 16:35:26
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
create table [tb]([value] varchar(8))
insert [tb]
select 'ABxBAxA' union all
select 'BxBABxAA' union all
select 'BxBAxAB' union all
select 'AxBxBAAx' union all
select 'BxABBxA'
--------------开始查询--------------------------
select * from tb where value like '%[A-Z]B[A-Z]B%'
----------------结果----------------------------
/*
value
--------
ABxBAxA
BxBABxAA
AxBxBAAx
(所影响的行数为 3 行)
*/