日期:2014-05-17 浏览次数:20490 次
create table jy
(x varchar(50))
insert into jy(x)
select 'AGD5-6888-6S-66' union all
select 'BDGH5-6888-6D-66' union all
select 'AGD5-688d8-6S-66' union all
select 'BDGH5-6888-6AD-66'
select x
from jy
where (charindex('GD',x,1)>0 or charindex('DGH',x,1)>0)
and substring(x,
case when charindex('GD',x,1)>0 then charindex('GD',x,1)+10
when charindex('DGH',x,1)>0 then charindex('DGH',x,1)+11 end
,1) in ('S','D')
/*
x
--------------------------------------------------
AGD5-6888-6S-66
BDGH5-6888-6D-66
(2 row(s) affected)
*/
If not object_id('[tb]') is null
Drop table [tb]
Go
Create table [tb]([str] nvarchar(17))
Insert [tb]
Select N'AGD5-6888-6S-66' union all
Select N'BDGH5-6888-6D-66' union all
Select N'AGD5-688d8-6S-66' union all
Select N'BDGH5-6888-6AD-66'
Go
--
Select * from [tb] where PATINDEX('%GD_________[SD]%',str)>0 or PATINDEX('%DGH_________[SD]%',str)>0
/*
str
-----------------
AGD5-688d8-6S-66
BDGH5-6888-6AD-66
(2 行受影响)
*/
select str from [tb] where str like '%GD________[SD]%' or str like '%DGH________[SD]%'