This topic is locked
[SOLVED]

 SQL query SUBTRACT two fields...?

12/15/2006 9:06:28 AM
PHPRunner General questions
S
siegfried.hansen author

Hello again,
I have this table called "invoices" and the fields called "invoice_value", "paid_amount" and "difference".

What I need is to get in the "difference" the result from "invoice_value - paid_amount".
Using in version 3.1, on SQL query window:
UPDATE invoices

SET difference = invoice_value - paid_amount

is always giving the "Cannot retrieve columns information..." error message; though, the query is working like a charm in MS Access...what am I doing wrong??
All fields are INT types.
Thanks...again.
Cheers!
Sieg

Alexey 12/15/2006

Sieg,
the Edit SQL query tab supports SELECT queries only.
Please clartify what do you want to do with this query and I'll help you to implement this.

S
siegfried.hansen author 12/15/2006

Sieg,

the Edit SQL query tab supports SELECT queries only.
Please clartify what do you want to do with this query and I'll help you to implement this.


Alexey,
Basically it's an invoice keeper from where different types of reports can be retrieved.

I'm not an accountant however but our finances-guru told me that, in order to have a clear image of the invoices to our clients, he needs these three fields as follows ( beside others which arent relevant here) :

  1. invoice_value - keeps the value of the invoices sent to our customers;
  2. paid_amount - the money paid effectively by the clients;
  3. difference - due to some reasons I'm not familiar with, it seems like sometime the clients are paying less money than the amount of the invoices, so this field should be the difference between the first two ( 1 minus 2 ).
    That's it. I tried lots of things and, waiting for an answer here, I've been looking on the Help files - I should do it earlier <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=13924&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' /> - and it says exactly what you said above. However if you can help me with this would be great.
    Thanks a lot.
    Cheers!
    Sieg

Alexey 12/15/2006

Sieg,
I see what you saying.
I recommend you to ignore "difference" field and use a calcualted field instead of it.

I.e. modify your SQL query this way:

select

invoice_value,

paid_amount,

invoice_value - paid_amount as diff

from invoices

S
siegfried.hansen author 12/15/2006

Alexey,
It worked.
Thank you so much indeed! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=13927&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
Cheers!
Sieg