Board index » delphi » Parambyname doesn't work.

Parambyname doesn't work.

Hi,

I have a TQuery component in Delphi5 looking at a paradox table. I attempt
to assign values to the query, but for some reason, the query seems to
ignore the values I send to it. Can someone please help.

The SQL in the query is as follows:

SELECT DISTINCT Contpackdet.PRODUCT, Contpackdet.VARIETY, Contpackdet.GRADE,
sum(tickets.nett) as Total
FROM "Tickets.DB" tickets
INNER JOIN "contpack.DB" ContPack
ON (ContPack.CONTRACT = tickets.ContractTo)
INNER JOIN "ticketsera.DB" Ticketsera
ON (Ticketsera.Ticket = tickets.Ticket)
INNER JOIN "contpackdet.DB" Contpackdet
ON (ContPack.CONTRACT = Contpackdet.CONTRACT)
WHERE

(ContPack."Exporters Code" = :ex) AND
(Tickets.DateTime >= :ds) and
(Tickets.DateTime <= :de)
GROUP BY Contpackdet.PRODUCT, Contpackdet.VARIETY, Contpackdet.GRADE

I then run the following script:

Query1.close;
Query1.ParamByName('ds').Value := '07/01/2001 00:00:00'; {Date Start}
Query1.ParamByName('de').Value := '06/30/2001 23:59:59';  {Date End}
Query1.open;

(The Paramaters Datatype is of ftDateTime)

And the query gives me results!!!! Of course, if the date end date is less
than the date start date, you would expect the query to return no results.
If I type in the dates manually into the query - I get no results, but if I
use the codes above, I get results!?!

Can someone please help me - this is happening to most of my queries that I
use Parambyname on DateTime fields in Paradox tables!

Thanks & regards

Adam

 

Re:Parambyname doesn't work.


"Adam H." <ah...@netconnect.com.au> skrev i en meddelelse
news:3b527273_1@dnews...

Quote
> (ContPack."Exporters Code" = :ex) AND
> (Tickets.DateTime >= :ds) and
> (Tickets.DateTime <= :de)
> GROUP BY Contpackdet.PRODUCT, Contpackdet.VARIETY, Contpackdet.GRADE
> I then run the following script:
> Query1.close;
> Query1.ParamByName('ds').Value := '07/01/2001 00:00:00'; {Date Start}
> Query1.ParamByName('de').Value := '06/30/2001 23:59:59';  {Date End}
> Query1.open;
> (The Paramaters Datatype is of ftDateTime)

You should use a proper datetime value like this:
Query1.ParamByName('ds').AsDateTime := dtDateStart;
Query1.ParamByName('de').AsDateTime := dtDa{*word*249}d;
And you forgot to set the :ex parameter.

Finn Tolderlund

Re:Parambyname doesn't work.


The .Value property is a variant so when you assign a string to it, even
though the string contains a date and time, the parameter type is a string.
Try

Query1.close;
Query1.ParamByName('ds').AsDateTime := StrToDateTime('07/01/2001 00:00:00');
{Date Start}
Query1.ParamByName('de').AsDateTime := StrToDate('06/30/2001 23:59:59');
{Date End}
Query1.open;

--
Bill

Re:Parambyname doesn't work.


Hi Bill and Finn,

Sorry for the late reply, but thank you so very much. Works wonderful!

Adam.

Other Threads