On 7/17/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Hello, and thanks for the reply.
SELECT *
from Employees
where IDContractLevel > 4
is not enough, since I actually need to use a field that is created inside the
SQL statement to create another field. The problem is that it seems that the
computed fields is not existing yet when it is used for another field.
The example I posted was only a "stupid" example of what I mean, just to
clarify the situation. Another example would be this:
SELECT TotalInvoice, (SELECT SUM(PaymentValue) FROM Payments WHERE
Payments.IDInvoice = IDInvoice) AS TotalPaid, TotalPaid = TotalInvoice AS
FullyPaid FROM Invoices;
You can't use the aliased column TotalInvoice since it doesn't exist until
after the query is executed.
You could do the boolean operation manually in your code, or
You might try to create a view from this query:
Create view Myview AS
SELECT TotalInvoice, (SELECT SUM(PaymentValue) FROM Payments
WHERE Payments.IDInvoice = IDInvoice) AS TotalPaid,
IDInvoice
FROM Invoices;
Then select from the view:
SELECT TotalInvoice, TotalPaid, TotalInvoice = TotalPaid AS FullyPaid
FROM Myview
WHERE IDInvoice = XXXX