日期:2014-05-18  浏览次数:20413 次

一个简单的语句,急!!!
我有一个表,其中有个letter字段,这个字段的值都是单个小写字母,如a,b,e之类的
id letter
1 a
2 b
3 a
4 y

我现在想获取letter中含有a,b,c这些其中一个字母的记录,我用charindex
select * from table where charindex(letter,'abc')>0
不过这个语法不对呀
select * from table where charindex('a',letter)>0
这个是执行的,不过仅能获取letter中有a的记录。

怎么写呀,谢谢。

------解决方案--------------------
select * from table where charindex(letter,'a')> 0 or charindex(letter,'b')> 0 or charindex(letter,'c')> 0

------解决方案--------------------
SQL code
--try
select * from [table]
where letter in ('a','b','c')

------解决方案--------------------
SQL code

select   *   from   [table]   where   patindex('%[a b c]%',letter)> 0

------解决方案--------------------
SQL code

declare @t table (id int,letter varchar(20))
insert into @t
select 1,'a'
union all select 2,'b'
union all select 3,'c'
union all select 4,'d'
union all select 5,'a'
union all select 6,'e'
--方法一
select * from @t where letter in ('a','b','c')
--方法二
select * from @t where letter='a' or letter='b' or letter='c'