Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Aliases in the Where clause??Hlp pls

Status
Not open for further replies.

Fori

Programmer
Jun 18, 2003
84
MT
Hi

i have a quite big sql statement and i would like to ask u if its possible to use aliases in the Where clause and if it is how to use it.

What i'm trying to do is:

SELECT
(SELECT sum(amount) From invoiceDB WHERE Invoice_CustomerID = CustomerID) AS P1

FRom CustomerDB WHERE P1 > 0

Is the above possible?

Thanks
Nick
 
try something like this:

SELECT P1
FROM(SELECT SUM(Amount) P1, CustomerID FROM InvoiceDB GROUP BY CustomerID)
WHERE P1> 0


-Rick
 
In answer to your general question:

Is it possible to use aliases in the Where clause?

No, you can't do this (although you can refer to aliases in the ORDER BY clause).

--James
 
Thanks james!!

So if i have a big nested select i have to repeat it agian in the where clause?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top