我现有表tb_warehouse_detailed
字段有
billdate billcode tradecode
--------------------------------------------
2009-04-03 20090503JH0001 T00001
2009-04-04 20090504JH0002 T00001
2009-04-05 20090505JH0003 T00002
..............................我想实现在时间段(billdate)中查询字段billcode 、tradecode的数据,怎写?请教。
以下只是实现时间段查询,但不能加字段billcode 、tradecode查询?
var
sqlstr:string;
a,b,e:string;
begin
b:=datetostr(DateTimePicker1.date);
e:=datetostr(DateTimePicker2.date);
a:='select * from tb_warehouse_detailed where billdate between '+QuoTedStr(b)+' and '+QuoTedStr(e);
with ADOQuery do begin
with sql do begin
close;
clear;
ADOQuery.sql.Add(a);
end;
open;
DBGrid1.DataSource:=EQDS;
end;
字段有
billdate billcode tradecode
--------------------------------------------
2009-04-03 20090503JH0001 T00001
2009-04-04 20090504JH0002 T00001
2009-04-05 20090505JH0003 T00002
..............................我想实现在时间段(billdate)中查询字段billcode 、tradecode的数据,怎写?请教。
以下只是实现时间段查询,但不能加字段billcode 、tradecode查询?
var
sqlstr:string;
a,b,e:string;
begin
b:=datetostr(DateTimePicker1.date);
e:=datetostr(DateTimePicker2.date);
a:='select * from tb_warehouse_detailed where billdate between '+QuoTedStr(b)+' and '+QuoTedStr(e);
with ADOQuery do begin
with sql do begin
close;
clear;
ADOQuery.sql.Add(a);
end;
open;
DBGrid1.DataSource:=EQDS;
end;
建议多看书
如果想多字段条件查询,那就加几个And吗
a:='select * from tb_warehouse_detailed where (billdate between '+QuoTedStr(b)+' and '+QuoTedStr(e)+') and billcode=xxx and tradecode=xxx';
DateTimePicker1 DateTimePicker1 edit1 edit2
a:='select * from tb_warehouse_detailed where (billdate between '+QuoTedStr(b)+' and '+QuoTedStr(e)+') and (tradecode like'''+'%'+ComboBox1.Text+'%'') and (billcode like'''+'%'+ComboBox2.Text+'%'')';