How to calculate a value in the middle of a SQL query one time, use repeatedly
Posted on 2014-12-12
For better or worse, I have a query which looks similar to this:
select a, b, c, (select d from e where f=g) as h from table where h=i
But I get "invalid column name h". So I have to repeat the sub-query like this:
select a, b, c, (select d from e where f=g) as h from table where (select d from e where f=g)=i
In my actual code, the sub-query is a lot more complex, and having to run it over and over again is causing timeout errors. How can I create that sub-query, run it just one time, but use it in the where clause?
I am doing this with ASP, so I have to run it in a single query statement.