SQL Help, using the Params value of an TQuery Dynamically - D3

I am working on a scheduling project where the form contains a DBGrid,
and a Calendar component.

I have two underlying tables : Customer, and Profile ...
The Field "CustNum" is the index and resides in both tables..

The form has two queries with both database properties set to the same
alias, and when the form launches, the DBGrid is set to ScheduleQuery's
datasource and it's SQL statemment is as below: (no Parameters ...)

select c.Company, p.NextServiceDate
from customer c, profile p
where c.custnum = p.custnum
order by p.NextServiceDate

This work's fine, and shows all the customer's from the Customer table,
and the thier "NextServiceDate" respectively ...

My objective is, when the calendar is clicked, Filter the records to the
date the user selected on the calendar component, (via the secondary
TQuery named "ParamQuery") then switch the DBGrid's datasource to the
other ParamQuery's datasource to show the result.

Here is the SQL statement for the secondary ParamQuery:
select  c.Company, p.NextServiceDate
from customer c, profile p
where p.custnum = c.custnum AND p.NextServiceDate = :TheCalendarDate
order by p.NextServiceDate

At design time, the Parameter "TheCalendarDate" is defined in the SQL
statement and shows up in the Params editor, and I have set it's data
type to Date with nothing entered in the Value edit box..

Now here's where the problem lies..  I am trying to dynamically set the
value for "TheCalendarDate" to filter the records..

I am trying the lines of code below in the calendar's OnClick event, and
getting nothing but errors..

(The "NextServiceDate: field is of type TDateTime)
ScheduleDBGrid.DataSource := ScheduleQuery.DataSource;

then I try these three variations ...

ScheduleQuery.ParamByName('TheCalendarDate').AsDateTime :=  
Calendar.CalendarDate; {Calender.CalendarDate property is also Type :
{results in a error: "Parameter 'TheCalendarDate' not found!"}


ScheduleQuery.Params[0].Value := Calendar.CalendarDate;
{results in an "Index out of bounds" error}


hardcode it with ...

ScheduleQuery.ParamByName('TheCalendarDate').Value :=
{again, results in a "Parameter 'TheCalendarDate' not found!" error}  

Sorry for this long drawn out post, but this is driving me crazy...

I originally tried to build this form with filtering concepts with the
TTable's connected, with no luck.  Overall I think SQL would be a better
choice because it can combine data from two separate tables in one

Any help would be greatly appreciated!!


         ( 0 0 )
Reid Roman
E-Mail : rkroman (at) pacbell (dot) net
Delphi Enthusiast, Hobbyist ..