Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

How to limit a Query

edited July 2002 in General
I am using Delphi 5 and RB enterprise ... things are going well but I have a
report in which I need to allow the user to set a data range ... how can I
let a start and ending date figure into a query that drives my report? I
guess I could set up a table with a start and ending date that can be set on
before print by the user. I can then link these dates into the query. Is
this the recommended way or is there a better way? Thanks, LL

Comments

  • edited July 2002
    Why don't you create a form to ask the user the dates tange he wants to use and
    then open the report?

  • edited July 2002
    That's what I want to do but how do I limit the query based on the dates he
    supplies. I don't see with RB how to insert a variable. LL
  • edited July 2002
    Using parameters on the query.
    It has nothing to do with RB in particular.
    Just create a query like:

    SELECT ...
    WHERE YourDateField BETWEEN :DateIni and :DateEnd

    Then set the proper values to the parameters

    MyQuery.ParamByName('DateIni').AsDate := TheIniDateSuppliedForTheUser;
    MyQuery.ParamByName('DateEnd').AsDate := TheEndDateSuppliedForTheUser;
    MyQuery.Open;
    MyReport.Print;

  • edited July 2002
    Thanks but I figured it out ... set search fields in the query and then set
    code ... for example
    if (ppReport1.AutoSearchFields[0].FieldName = 'IncidentDate') then
    begin
    ppReport1.AutoSearchFields[0].SearchExpression:=LowDate;
    ppReport1.AutoSearchFields[1].SearchExpression:=HighDate;
    end;

    thanks, LL
  • edited July 2002
    Now i have a question for the DM team... does the AutoSearchFields apply a WHERE
    clause to the underlying Query or filter the data locally?

  • edited July 2002
    Hi Guillermo,

    the WHERE clause is involved. See page 'SQL' in the data designer.

    regards,
    Chris Ueberall;

  • edited July 2002
    If you need to first 30 or so from the query you could also do it like this
    :


    SELECT *
    FROM Table
    WHERE
    LIMIT 30

    then it should limit the output to 30 max

    regards Paul


  • edited July 2002
    Hi Paul,

    your given statement is database depending and therefore not supported for
    all databases.

    regards,
    Chris Ueberall;

  • edited July 2002
    Yep, but it doesn't work on all the databases

  • edited July 2002
    Check out the AutoSearch demos found in RBuilder\AutoSearch. You can create
    a dialog to query values from the user and then inject them into the query
    object.

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

This discussion has been closed.