飘雪图片大全:在vb中的查询语句?

来源:百度文库 编辑:高考问答 时间:2024/04/28 04:47:42
假如一个表

考试号 姓名 ....

10023 李四 ....

10025 张三 ...

要查询考试号前三位为100的记录,SQL语句怎么写啊?
谢谢各位给的答案,我再补充一点,前三位为100只是个举例,更普遍的是前三位在combo1中选择,我是这样写的
"select * from lesson where 课程编号 like '" + Combo1.Text + "%'",可是查不出来,不知道哪错了

楼主首先要确定一下“考试号”字段是否为字符型。如不是需要进行转换再查询,如
select * from 表1 where left(convert(char,考试号),3)='100'

VB环境与SQL语句没有关系,它只是传递一条指令给Database运行环境。SQL语句的写法依赖于数据库环境的具体条件。
譬如在Oracle中:
select * from tablename where 考试号 like '100%'
或者
select * from tablename where substr(考试号,0,3) = '100'

select 考试号,姓名 from 表名 where 考试号 like '100%'
如果你的表的字段很多,但是你查询几个字段的话,最好不要用select *,而是只选择你用的字段

select top 3 * from 表1 where 考试号 like '100%' order by 考试号

select * from 表名 where 考试号 like '100%'
这条语句应该足够了。

select * from 表1 where left(考试号,3)='100'