怎样将二个查询条件合并到一起呢!!急!赏分!!

来源:百度知道 编辑:UC知道 时间:2024/06/10 02:21:37
我做了两个复选框.单选时都能实现各自的功能.可要是双选就不行,只能实现第一个选项,第二项如同虚设.比如..我想查找,1999-1-1到2008-1-1的所有数据要怎么做...
If Check1.Value = 1 Then
sql = "select * from yhda where " & xm & " like '%" & txtcz.Text & "%'ORDER BY yhid DESC"
ElseIf Check2.Value = 1 Then
sql = "select * from yhda where gjrq between #" & DTP1 & "# and #" & DTP2 & "#"
End If
Ado1.RecordSource = sql '定义数据源,构造SQL语句
Ado1.Refresh
Set DataGrid1.DataSource = Ado1 '为DataGrid1赋值
DataGrid1.Refresh

分不多!!可心意重,,请各位大虾们帮指点一下.....
忘了注明我是用VB编的...'上面的语句完成条件的构造,但是始终以and开头,下面一句删除第一个对于的and
cond=right(cond,len(cond)-4)
不是很明白...能清楚点吗..因为没用过COND这东东
我的意思是,先在第一项查找框中输入内容后进行模糊查询,再用模糊查询所得的内容进行时间段的查询.
例如:我先查姓名中所有姓李的...然后再将查询到的所有姓李的并符合时间段输出DataGrid1显示..

那就下面这样:

cond=""
If Check1.Value = 1 Then
cond=cond & " and " & xm & " like '%" & txtcz.Text & "%'"
end if
If Check2.Value = 1 Then
sql = " and gjrq between #" & DTP1 & "# and #" & DTP2 & "#"
End If
'上面的语句完成条件的构造,但是始终以and开头,下面一句删除第一个对于的and
cond=right(cond,len(cond)-4)
'下面的语句完成查询语句的构造,可以任意选一个,也可以选两个
sql = "select * from yhda where " & cond & " ORDER BY yhid DESC"
Ado1.RecordSource = sql '定义数据源,构造SQL语句
Ado1.Refresh
Set DataGrid1.DataSource = Ado1 '为DataGrid1赋值
DataGrid1.Refresh

你实现的是不是时间段的查询?可以用BDE中的query实现 是delphi软件设计的
var str1:tdate;
str2:tdate;
begin
str1:=self.DateTimePicker1.Date-2;
str2:=self.DateTimePicker2.Date-2;
try
with JHXXJM.Query1 do
begin
Close;
with SQL do
begin
Clear;
Add('select 你要查询