ADOQuery Filter

I am having trouble making this code work, it gives me an error that says the parameters are not correct or of the wrong type. I have tried several variations and I can't seem to find one that works.

This is in an OnClick event for an Ok button.

begin
if CheckBox1.Checked = False then
begin
Query1.Filtered := False;
Query1.Filter := "[TARGTAREA]= 'OTA'";
Query1.Filtered := True;
end
else
begin
Query1.Filter.Active := False;
end;
end

If I manually set the filter in the query to [TARGTAREA] = 'OTA' it works OK.

The query is
SELECT x8.TARGTAREA, Count(x2.UniqueID) AS CountOfUniqueID, x2.TASKCODE, x2.TASKMAJR
FROM xprop AS x8, xbldg AS x, xunit AS x11, xloc AS x6, xsurf AS x9, xcase AS x2
WHERE (((x8.SEQ)=[x].[seq]) AND ((x.BSEQ)=[x11].[bseq]) AND ((x11.USEQ)=[x6].[useq]) AND ((x6.LSEQ)=[x9].[lseq]) AND ((x9.SSEQ)=[x2].[sseq]))
GROUP BY x8.TARGTAREA, x2.TASKCODE, x2.TASKMAJR
HAVING (((x8.TARGTAREA) Like :Target))
ORDER BY x8.TARGTAREA, Count(x2.UniqueID) DESC , x2.TASKCODE;

Comments

  • edited 11:11AM
    If your ADOQuery.SQL contains exactly 6 lines of code as you wrote
    SELECT x8.TARGTAREA, Count(x2.UniqueID) AS CountOfUniqueID, x2.TASKCODE, x2.TASKMAJR
    FROM xprop AS x8, xbldg AS x, xunit AS x11, xloc AS x6, xsurf AS x9, xcase AS x2
    WHERE (((x8.SEQ)=[x].[seq]) AND ((x.BSEQ)=[x11].[bseq]) AND ((x11.USEQ)=[x6].[useq]) AND ((x6.LSEQ)=[x9].[lseq]) AND ((x9.SSEQ)=[x2].[sseq]))
    GROUP BY x8.TARGTAREA, x2.TASKCODE, x2.TASKMAJR
    HAVING (((x8.TARGTAREA) Like :Target))
    ORDER BY x8.TARGTAREA, Count(x2.UniqueID) DESC , x2.TASKCODE;
    

    then try to make a dynamic change in THIS ADOQuery within FR script in any event when your report knows what parameters (for TargetArea) are chosen and before THIS ADOQuery is open. I mean 5th line of your select statement holds where clause

    ADOQuery1.SQL[ 5] := 'HAVING ...'; // and here should be a string you create on-fly,

    where you can manipulate with a string that you assign to ADOQuery1.SQL[ 5] making whole SELECT statement being acceptable by your database engine syntax.

    Mick

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.