使用德尔福 XE2。
我有一个数据库软件包,可以将表中的记录显示到 cxgrid 上。我已经实现了一个过滤器按钮,单击它允许用户使用特定记录搜索结果。At the moment it only works when 1 of the records is selected, it doesn't like it when more than one of the filter records is selected, it displays the following error....'syntax error or access violation: near 'and '在...[和]'。以下代码是我在单击过滤器按钮时正在执行的操作。
任何帮助将非常感激。
begin
with dmData.aQry do
begin
Close;
SQL.Clear;
SQL.Text:= ('select * from DBA.RECORDS');
if dbluCaseCategory.Text <> '' then SQL.Add('where category_type like :category_type');
if dbluSubCategory.Text <> '' then SQL.Add('and sub_cat_type like :sub_cat_type');
if dbluCustomer.Text <> '' then SQL.Add('and customer_name like :customer_name');
if dbluUsername.Text <> '' then SQL.Add('and created_by_user like :created_by_user');
if cxStartDateEdit.Text <> '' then SQL.Add('and logged_dt like :logged_dt');
if dbluCaseCategory.Text <> '' then ParamByName('category_type').Value := dbluCaseCategory.Text +'%';
if dbluSubCategory.Text <> '' then ParamByName('sub_cat_type').Value := dbluSubCategory.Text +'%';
if dbluCustomer.Text <> '' then ParamByName('customer_name').Value := dbluCustomer.Text +'%';
if dbluUsername.Text <> '' then ParamByName('created_by_user').Value := dbluUsername.Text +'%';
if cxStartDateEdit.Text <> '' then ParamByName('logged_dt').Value := cxStartDateEdit.Text +'%';
Open;
end;
Close;
end;