if CheckBox1.Checked then
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from spsellsum where 客户 like ''%'+edit1.text+'%''');
end
else begin
adoquery1.sql.close;
adoquery1.SQL.Add('select * from spsellsum where 销售日期>=:date1 and 销售日期 <=:date2 ');
adoquery1.Parameters.ParamByName('date1').Value:=datetostr(datetimepicker1.Date);
adoquery1.Parameters.ParamByName('date2').Value:=datetostr(datetimepicker2.Date); end;
adoquery1.open;不知道理解多没?
if not CheckBox1.Checked then
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from spsellsum where 客户 like ''%'+edit1.text+'%''');
end
else begin
adoquery1.sql.close;
adoquery1.SQL.Add('select * from spsellsum where 销售日期>=:date1 and 销售日期 <=:date2 ');
adoquery1.Parameters.ParamByName('date1').Value:=datetostr(datetimepicker1.Date);
adoquery1.Parameters.ParamByName('date2').Value:=datetostr(datetimepicker2.Date); end;
adoquery1.open;
搞反了
if not CheckBox1.Checked then
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from spsellsum where 客户 like ''%'+edit1.text+'%''');
end
else begin
adoquery1.sql.close;
adoquery1.SQL.Add('select * from spsellsum where 客户 like ''%'+edit1.text+'%'' and 销售日期>=:date1 and 销售日期 <=:date2 ');
adoquery1.Parameters.ParamByName('date1').Value:=datetostr(datetimepicker1.Date);
adoquery1.Parameters.ParamByName('date2').Value:=datetostr(datetimepicker2.Date); end;
adoquery1.open;
adoquery1.SQL.Add('select * from spsellsum where 销售日期>=:date1 and 销售日期 <=:date2 ');
adoquery1.Parameters.ParamByName('date1').Value:=datetostr(datetimepicker1.Date);
adoquery1.Parameters.ParamByName('date2').Value:=datetostr(datetimepicker2.Date); end;这个是统计全部这个时间段的,但是我的要求是,CheckBox1选中的时候,要加入前面的combobox的条件来筛选
这个应该不难吧,sql 我不怎么在行,像上面的再加1个条件试试。
begin
if not CheckBox1.Checked then
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from spsellsum where 客户 like ''%'+edit1.text+'%''');
adoquery1.Open;
end
else begin
adoquery1.sql.Clear;
adoquery1.SQL.Add('select * from spsellsum where 客户 like ''%'+edit1.text+'%'' and 销售日期>=:date1 and 销售日期 <=:date2 ');
adoquery1.Parameters.ParamByName('date1').Value:=datetostr(datetimepicker1.Date);
adoquery1.Parameters.ParamByName('date2').Value:=datetostr(datetimepicker2.Date);
adoquery1.open;
end;end;
kfcoffe 他上面写的有一个错误,这个是我根据他写的改好了,但是如果这样,如果COMBOBOX1有多个条件,就要写重复多个判断,那变有点画长龙呢,嘿嘿如果没有更好的代码,明天就结贴了。
if not CheckBox1.Checked then
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from spsellsum where 客户 like ''%'+edit1.text+'%''');
end
else begin
adoquery1.sql.close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from spsellsum where '+ComboBox1.Text+ ' like ''%'+edit1.text+'%'' and 销售日期>=:date1 and 销售日期 <=:date2 ');
adoquery1.Parameters.ParamByName('date1').Value:=datetostr(datetimepicker1.Date);
adoquery1.Parameters.ParamByName('date2').Value:=datetostr(datetimepicker2.Date);
end;
adoquery1.open;
如果没就不加这两个and
if checked then
begin
adoquery1.SQL.Add(' and 销售日期>=:date1 and 销售日期 <=:date2 ')
adoquery1.Parameters.ParamByName('date1').Value:=datetostr(datetimepicker1.Date);
adoquery1.Parameters.ParamByName('date2').Value:=datetostr(datetimepicker2.Date);
end;
如果你combo中text和数据库中字段名相同没有必要判断每个combo选项情况
就算不同也可以用个array代替
adoquery1.SQL.Add('select * from spsellsum where'+combobox1.Text+' like ''%'+edit1.text+'%''');或者adoquery1.SQL.Add('select * from spsellsum where'+champName[ComboBox1.ItemIndex]+' like ''%'+edit1.text+'%''');