我要求检查一个值是否仅包含前两个字符中的字母D,F,I,Q,U或V
在SQL中,我尝试过
LIKE '[DFIQUV][DFIQUV]%'
我做错了什么?
答案 0 :(得分:1)
分开检查前两个字符的每一个:
WHERE (COL LIKE '[DFIQUV]%' OR COL LIKE '_[DFIQUV]%')
答案 1 :(得分:0)
如果我理解正确,你需要这样的东西:
create table #a(col varchar(10))
insert #a(col)
select 'ABC' union all
select 'EFG' union all
select 'DFI' union all
select 'QUV'
--unnecessary rows
select * from #a where col not like '[DFIQUV][DFIQUV]%' --1st version (means 'and' condition between two letters)
select * from #a where col not like '[DFIQUV]%' or col like '_[DFIQUV]%' --correct version (manually 'or' condition)
--necessary rows
select * from #a where col not like '[DFIQUV]%' and col not like '_[DFIQUV]%'