Using Delphi XE2.
I have a database software package that shows a record from a table on a cxgrid. I have implemented a filter button with one click, allowing users to search for results using specific records. At the moment it works only when 1 out of records is selected, it is not liked, when more than one filter record is selected, it displays the following error .... 'syntax error or access violation : Pass' and 'more in']. The following code is what I am doing when I click on the filter button.
Any help would be greatly appreciated.
Start with DMDITA. SQL.Clear; SQL.Text: = ('Choose * from DBA.RECORDS'); If dbluCaseCategory.Text & lt; & Gt; '' So SQL Add ('where sort of category: category_type'); If dbluSubCategory.Text & lt; & Gt; '' Then SQL.Add ('and as sub_cat_type: sub_cat_type'); If dbluCustomer.Text & lt; & Gt; '' Then SQL.Add ('and customer_name like: customer_name'); If dbluUsername.Text & lt; & Gt; '' So, SQL.ad ('Made and Created Person: Like: Created' Person '); If cxStartDateEdit.Text & lt; & Gt; '' So SQL Add (like 'and log in: log-ddt'); If dbluCaseCategory.Text & lt; & Gt; '' Then Paramabine ('Category_type'). Value: = dbluCaseCategory.Text + '%'; If dbluSubCategory.Text & lt; & Gt; '' Then Paramabanam ('subcut_type'). Value: = dbluSubCategory.Text + '%'; If dbluCustomer.Text & lt; & Gt; '' Then the ultimate name ('customer_name'). Value: = dbluCustomer.Text + '%'; If dbluUsername.Text & lt; & Gt; '' Then the ultimate name ('made_by_user'). Value: = dbluUsername.Text + '%'; If cxStartDateEdit.Text & lt; & Gt; '' Then the ultimate name ('log in_date'). Value: = cxStartDateEdit.Text + '%'; Open; End; Close; End;
Your code will only work if you include the first filter (dbluCaseCategory.Text). Because if you add
where
to the code on that code, then if you do not pass any value fordbluCaseCategory
, then the last SQL Sentence will not be valid. To fix that just add awhere 1 = 1
to the first sentence. As soon as. Stop dmData.aqry with; SQL.Clear; SQL.Add (Select 'from DBA.records where 1 = 1'); If dbluCaseCategory.Text & lt; & Gt; '' Then SQL.Add ('and category_type like: category_type'); If dbluSubCategory.Text & lt; & Gt; '' Then SQL.Add ('and sub_cat_type like: sub_cat_type'); If dbluCustomer.Text & lt; & Gt; '' Then SQL.Add ('and customer_name like: customer_name'); If dbluUsername.Text & lt; & Gt; '' So, SQL.ad ('Made and Created Person: Like: Created' Person '); If cxStartDateEdit.Text & lt; & Gt; '' So SQL Add (like 'and log in: log-ddt'); If dbluCaseCategory.Text & lt; & Gt; '' Then Paramabine ('Category_type'). Value: = dbluCaseCategory.Text + '%'; If dbluSubCategory.Text & lt; & Gt; '' Then Paramabanam ('subcut_type'). Value: = dbluSubCategory.Text + '%'; If dbluCustomer.Text & lt; & Gt; '' Then the ultimate name ('customer_name'). Value: = dbluCustomer.Text + '%'; If dbluUsername.Text & lt; & Gt; '' Then the ultimate name ('made_by_user'). Value: = dbluUsername.Text + '%'; If cxStartDateEdit.Text & lt; & Gt; '' Then the ultimate name ('log in_date'). Value: = cxStartDateEdit.Text + '%'; Open;
No comments:
Post a Comment