September 13, 2011 at 1:09 pm
I want to calculate a column for a query as a function of table columns, say:
Select ColA*ColB*ColC as ColMultiple from tblCustomer....
Now, I'd like to calculate another column as a function of the first calculated column, say:
Select ColD/ColMultiple as ColAverage from tblCustomer....
Must I repeat the calculation of 'ColMultiple' each time I want to use that result, or is there a way to refer to the newly-calculated colum, say:
Select ColA*ColB*ColC as ColMultiple, ColD/ColMultiple as ColAverage from tblCustomer....
I know that doesn't work... is there a way to do it?
Jim
September 13, 2011 at 1:17 pm
You can use a CROSS APPLY.
SELECT ColMultiple, ColD/ColMultiple as ColAverage
FROM tblCustomer
CROSS APPLY (
SELECT ColA*ColB*ColC as ColMultiple
) AS cm
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy