Board index » delphi » TQuery calculated field and logical operator

TQuery calculated field and logical operator

I have the following SQL strings in my TQuery component:

Select O.OrderNo, O.CustNo,
       (O.ItemsTotal - O.AmountPaid)  as AmountDue  { This works }
       (O.ItemsTotal > O.AmountPaid)  as Log2       { This does not
work}  
       FROM ORDERS O, CUSTOMER C
       where  O.CUSTNO = C.CUSTNO
       ORDER BY Log2

The calculated field AmountDue works OK, but if I use the logical '>'
operator
it does not work. Does anybody know if  the logical operation also
should work,
or is there any work-around to get it to work.

The idea is to get the Query result sorted according the calculated
True/False
field.

Markku Nevalainen

 

Re:TQuery calculated field and logical operator


Hi Markku

You could try a union:

SELECT O.OrderNo, O.CustNo, (O.ItemsTotal - O.AmountPaid) as AmountDue
        FROM ORDERS O, CUSTOMER C
        WHERE O.CUSTNO = C.CUSTNO AND O.ItemsTotal > O.AmountPaid
UNION SELECT O.OrderNo, O.CustNo, (O.ItemsTotal - O.AmountPaid) as
AmountDue
        FROM ORDERS O, CUSTOMER C
        WHERE O.CUSTNO = C.CUSTNO AND O.ItemsTotal <= O.AmountPaid

If you omit the ORDER clause, the record should be in your desired
order.

HTH

Klaus

On Tue, 22 Apr 1997 10:56:54 -0700, Markku Nevalainen

Quote
<mneva...@netlife.fi> wrote:
>I have the following SQL strings in my TQuery component:

>Select O.OrderNo, O.CustNo,
>       (O.ItemsTotal - O.AmountPaid)  as AmountDue  { This works }
>       (O.ItemsTotal > O.AmountPaid)  as Log2       { This does not
>work}      
>       FROM ORDERS O, CUSTOMER C
>       where  O.CUSTNO = C.CUSTNO
>       ORDER BY Log2

>The calculated field AmountDue works OK, but if I use the logical '>'
>operator
>it does not work. Does anybody know if  the logical operation also
>should work,
>or is there any work-around to get it to work.

>The idea is to get the Query result sorted according the calculated
>True/False
>field.

>Markku Nevalainen

Other Threads