首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

一个简略的语句,

2012-07-29 
一个简单的语句,急!!!我有一个表,其中有个letter字段,这个字段的值都是单个小写字母,如a,b,e之类的id lett

一个简单的语句,急!!!
我有一个表,其中有个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
--tryselect * 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 @tselect 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' 

热点排行