Select * From T Where id like 'A%' or id like 'B%'
select * from tbl where id id like 'A%' or id like 'B%'
Select * From T Where UPPER(Left(ID,1)) In ('A','B','C'....)
where Left(colname,1) In ('A','B'); where colname like 'A%' or colname like 'B%' where charindex('A', colname)=1 or charindex('B', colname)=1;
Select * From T Where id like 'A%' or id like 'B%' --数据库会用到索引,会提高查询效率
玩种新写法select * from tab where charindex('a',left(id,1))>0 or charindex('b',left(id,1))>0
SELECT * FROM TB WHERE ASCII(ID) > 64 AND ASCII(ID) < 67
Select * From T Where id like 'A%' or id like 'B%'
SELECT * FROM TB WHERE ASCII(ID) > 64 AND ASCII(ID) < 67
select * from t where id like 'A%' OR ID LIKE 'B%'
基于效率考虑。 where Left(colname,1) In ('A','B'); where charindex('A', colname)=1 or charindex('B', colname)=1;300万条记录 like 和 charindex 函数性能比较 . 可参考下文 http://blog.csdn.net/fanweiwei/article/details/4372459
Select * From T Where UPPER(Left(ID,1)) In ('A','B','C'....)
where colname like 'A%' or colname like 'B%'
where charindex('A', colname)=1 or charindex('B', colname)=1;
--数据库会用到索引,会提高查询效率
where charindex('a',left(id,1))>0
or charindex('b',left(id,1))>0
where Left(colname,1) In ('A','B');
where charindex('A', colname)=1 or charindex('B', colname)=1;300万条记录 like 和 charindex 函数性能比较 . 可参考下文
http://blog.csdn.net/fanweiwei/article/details/4372459