• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 493
  • Last Modified:

Parameterised query Delphi

I am new to Delphi but it is great for knocking out a quick query from Paradox.
I attach the code on a button which pulls data from 2 tables; Orders and dates.
You will note that the SQL WHERE command is month = 8.
I would like to change this to read the value of an Edit field on the form, so a user can select a month. So month = (Edit1.value).
I have looked at Tparams but my head hurts.
Could anybody point me the way forward, please? Note the month is an accounting month, not  calender month so I cannot play with a date field.
1 Solution
Geert GruwezOracle dbaCommented:
change the query text to accept a parameter first and then fill in the month
Query2.SQL.Add('SELECT  D.Delivered,  SUM(D.Nett) ' );
 Query2.SQL.Add(' FROM "GOOrders.DB" D, "vvdates.DB" D1  WHERE  (D1.Keydate = D.Delivered)AND D1.Months = :SELMONTH GROUP BY D.Delivered ORDER BY D.Delivered ');
Query2.ParamByName('SELMONTH').AsInteger := StrToInt(Edit1.Text);
Series1.DataSource := Query2 as tcomponent;
series1.XLabelsSource := 'Delivered';
series1.XValues.ValueSource := 'Delivered';
series1.yValues.ValueSource := 'Sum of nett';

Open in new window

you could
Query2.ParamByName('SELMONTH').AsString := Edit1.Text;

but if the edit1 is empty it will not give any records
and like this it throws an exception

>> when my head hurts, i use an aspirine
ClaytonGlassAuthor Commented:
I tried aspirin but your solution is much better!
Thank you very much!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now