34,587
社区成员
发帖
与我相关
我的任务
分享
declare @s table(col varchar(100))
insert @s
select
'qq-001-100' union select
'qq-001-100R' union select
'bb-123-234' union select
'bb-256-100R0' union select
'bb-256-100R1' union select
'bb-256-100R9' union select
'cc-678-123B'
select *
from @s
where not (PATINDEX( '%[RB]',col) > 0 or PATINDEX( '%[R][0-9]',col) > 0)
declare @t table(val varchar(50))
insert into @t select 'qq-001-100'
insert into @t select 'qq-001-100R'
insert into @t select 'bb-123-234'
insert into @t select 'bb-256-100R0'
insert into @t select 'bb-256-100R1'
insert into @t select 'bb-256-100R9'
insert into @t select 'cc-678-123B'
select * from @t where
patindex('%[^RB]',val)>0
and
patindex('%R[0-9]',val)=0
select * from
(
select 'qq-001-100' as a union
select 'qq-001-100R' union
select 'bb-123-234' union
select 'bb-256-100R0' union
select 'bb-256-100RT1' union
select 'bb-256-100R9' union
select 'cc-678-123B' union
select 'bb-256-100B3' union
select 'bb-256-100R4' union
select 'bb-256-100R6'
) t
where right(a,1) not in ('R','B')
and a not like '%_R[0-9]'
-------------------------------
a
-------------
bb-123-234
bb-256-100B3
bb-256-100RT1
qq-001-100
(4 個資料列受到影響)
select * from @t where
patindex('%[^RB]',val)>0
and
patindex('%[^R0]',val)>0
and
patindex('%[^R9]',val)>0
declare @t table(val varchar(50))
insert into @t select 'qq-001-100'
insert into @t select 'qq-001-100R'
insert into @t select 'bb-123-234'
insert into @t select 'bb-256-100R0'
insert into @t select 'bb-256-100R1'
insert into @t select 'bb-256-100R9'
insert into @t select 'cc-678-123B'
select * from @t where val like '%[^r][^rb]'