August 22, 2009 at 6:03 am
Hi All,
How to use a column alias in an expression?
Example:-
------------------------------------------------------------
SELECT
Tran.Amount+Tran.Discount+Tran.Taxes AS [Nett]
--,[Nett] / 6.5 AS [Payable]
FROM
Tran
WHERE Tran.Amount > 10000
------------------------------------------------------------
How to use that computed column in another expression.
It is required Because if we use SubQuery for a specific column then for each time when we want that column, we have to pass a SubQuery.
How to Solve this?
August 22, 2009 at 8:09 am
Bhavin_Bhatt25 (8/22/2009)
------------------------------------------------------------
SELECT
Tran.Amount+Tran.Discount+Tran.Taxes AS [Nett]
--,[Nett] / 6.5 AS [Payable]
FROM
Tran
WHERE Tran.Amount > 10000
------------------------------------------------------------
If i'm correct, you have to use all 'actual' column names for the 'payable' derived column as well. I dont think you can use NETT derived column as a part of query.
August 24, 2009 at 7:06 am
You cannot use an alias in a the select/where/group by you would need to repeat your calculation.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
August 25, 2009 at 9:11 am
you could put it in a subquery if you really need to
SELECT [Nett] / 6.5 AS [Payable]
from (select Tran.Amount+Tran.Discount+Tran.Taxes AS [Nett]
from Tran
where Tran.Amount > 10000) v
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply