Hi,
We have a situation where we need to calculate a value in a select statement and then use the result of that calculation in another calculation in the same statement - something along the lines of:
SELECT ColumnA,
ColumnB,
ColumnC * Column D AS NewColumn,
NewColumn / ColumnE AS AnotherColumn
This doesn't work - NewColumn isn't available for use in a calculation. We can't practicably combine the two calculations as, in the real code, NewColumn is the result of a very large CASE statement, as is ColumnE.
What's the best way of achieving the desired result? We're going to cheat our way around this by adding a column to the table and calculating the value of NewColumn into it in a separate step, but that's hardly elegant. Is there a "proper" way of doing this?
Sorry if it's a daft question - I'm really not a SQL expert and our DBA left last year.
Thanks in advance,
Tony.