Board index » delphi » Sorting tables on calculated field

Sorting tables on calculated field

It would really make my day if I could find a way of sorting a Paradox
table according to the values in a calculated field.  Can anybody help?

Thanks

Graham Johnson

 

Re:Sorting tables on calculated field


Quote
Johnson IT wrote:

> It would really make my day if I could find a way of sorting a Paradox
> table according to the values in a calculated field.  Can anybody help?

Here is one combine TQuery from two Paradox tables:

Select O.OrderNo, O.CustNo,
       O.SaleDate,  O.DueDate, O.ItemsTotal,
       O.TaxTotal, O.AmountPaid,
       C.Custno, C.Company,C.Phone,
       (O.ItemsTotal - O.AmountPaid)  as AmountDue
       FROM ORDERS O, CUSTOMER C
       where  O.CUSTNO = C.CUSTNO
       ORDER BY AmountDue

The key word is "as", here AmountDue is the calculated value, and the
query will be sorted by it.
There is also an example of this in Delphi-1 online Help, but it
sure isn't too easy to find. Also when you have got used that
at least D1 Help is extremely short sentenced when discussing about
any SQL stuff.

Markku Nevalainen

Re:Sorting tables on calculated field


If you can produce the calculated field in terms of SQL, then you can
sort it in a query, as in:

  select name,age,service,age*service product from test order by product

"product" is an SQL "alias" for age*years.  I tested this query on a
Paradox table.

Quote
Johnson IT wrote:

> It would really make my day if I could find a way of sorting a Paradox
> table according to the values in a calculated field.  Can anybody help?

> Thanks

> Graham Johnson

Re:Sorting tables on calculated field


Quote
"Johnson IT" <j...@global.co.za> wrote:
>It would really make my day if I could find a way of sorting a Paradox
>table according to the values in a calculated field.  Can anybody help?

Sure: upload the table to your favorite SQL DBMS, then quey with a sort
on the calculated field, the download back to Paradox.

Cheaper: restructure the table to add a field to hold the place for your
calculated one. Scan the table from OPAL (use a TCursor for speed),
computing all calculated entries. Then Sort from Paradox on that field,
then restructure to remove it (or...why don't you just leave it in ? Of
course, it's not normal-form since it can be recomputed, but it could
spare you further manipulations of that kind.
-------------------------
   Frederic G. MARAND
  Agorus SA / OSI SARL
      f...@soon.com
-------------------------

Other Threads