zch:='Select * From (select * from piece_history where 日期时间 between ' + #39 + DateToStr(DateTimePicker1.Date) + ' ' + timetostr(datetimepicker3.Time) + #39 + ' and ' + #39 + DateToStr(DateTimePicker2.Date) + ' ' + timetostr(datetimepicker4.Time) + #39 +') as temptable where 钢种='''+trim(combobox1.Text)+'''' ; 这句话能够执行,可是没有结果,为什么呀?
zch:='select * from from piece_history where 日期时间 between ' + #39 + DateToStr(DateTimePicker1.Date) + ' ' + timetostr(datetimepicker3.Time) + #39 + ' and ' + #39 + DateToStr(DateTimePicker2.Date) + ' ' + timetostr(datetimepicker4.Time) + #39 +' and 钢种='''+trim(combobox1.Text)+'''';
用户选择什么条件,where 后面就加什么条件嘛 sql="select * from where 1=1" if 选择了条件1 then sql=sql+加条件1; if 选择了条件2 then sql=sql+加条件2; ..... if 选择了条件n then sql=sql+加条件n;
拼SQL var strSql: string; begin strSql := ' select * from table where 1=1'; if trim(edit1.text)<>'' then strSql := strSql + ' and a = :a'; ...... with adoquery1 do begin close; sql.text := strSql; if trim(edit1.text)<>'' then parameters.parambyname('a').value = trim (edit1.text); ...... Open; end; end;
这句话能够执行,可是没有结果,为什么呀?
sql="select * from where 1=1"
if 选择了条件1 then
sql=sql+加条件1;
if 选择了条件2 then
sql=sql+加条件2;
.....
if 选择了条件n then
sql=sql+加条件n;
strSql: string;
begin
strSql := ' select * from table where 1=1';
if trim(edit1.text)<>'' then strSql := strSql + ' and a = :a';
......
with adoquery1 do
begin
close;
sql.text := strSql;
if trim(edit1.text)<>'' then parameters.parambyname('a').value = trim
(edit1.text);
......
Open;
end;
end;