Dear experts, I’m trying to filter the result in dbgrid connected to adoquery, depending on user selection of 4 checkboxes, user can select one or more fileds to filter the data accordingly I have this code, and I don’t know h开发者_运维百科ow to pass "and/ or not pass" it if user select two or more checkboxes.
Vw_Activity.SQL.Text:='select * from Vw_Activity where ';
if CBEmployee.Checked then
begin
Vw_Activity.SQL.Add('Emp_Name_Ar=:x');
Vw_Activity.Parameters.ParamByName('x').Value:=emp Name.Text;
end;
if CBTask.Checked then
begin
Vw_Activity.SQL.Add('Category_Name=:y');
Vw_Activity.Parameters.ParamByName('y').Value:=Pro blemCat.Text;
end;
if CBIncharge.Checked then
begin
Vw_Activity.SQL.Add('Support_name_En=:h');
Vw_Activity.Parameters.ParamByName('h').Value:=Sup portstaff.Text;
end;
if CBstatus.Checked then
begin
Vw_Activity.SQL.Add('Request_Status=:k');
Vw_Activity.Parameters.ParamByName('k').Value:=Req uestStatus.Text;
end;
Vw_Activity.Active:=true;
waitting your help
you can rewrite your sql sentence to (check the final 1=1)
select * from Vw_Activity where 1=1
and then add each condition like this
Vw_Activity.SQL.Text:='select * from Vw_Activity where 1=1 ';
if CBEmployee.Checked then
begin
Vw_Activity.SQL.Add('AND Emp_Name_Ar=:x');
Vw_Activity.Parameters.ParamByName('x').Value:=emp Name.Text;
end;
if CBTask.Checked then
begin
Vw_Activity.SQL.Add('AND Category_Name=:y');
Vw_Activity.Parameters.ParamByName('y').Value:=Pro blemCat.Text;
end;
if CBIncharge.Checked then
begin
Vw_Activity.SQL.Add('AND Support_name_En=:h');
Vw_Activity.Parameters.ParamByName('h').Value:=Sup portstaff.Text;
end;
if CBstatus.Checked then
begin
Vw_Activity.SQL.Add('AND Request_Status=:k');
Vw_Activity.Parameters.ParamByName('k').Value:=Req uestStatus.Text;
end;
Vw_Activity.Active:=true;
精彩评论