I use a subquery in my select query which gives me an aggregate value, the subquery is of 4-5 lines and involves joins and conditions.
Now i need to use this value returned by the subquery in my outer query to do some calculation.
SELECT S.[SecurityId], S.[Service], (select count(Id) ----joins and conditions---- where Id = S.[SecurityId]) as [Total]
FROM TableName S
Now in my outer query i would like to use [Total] value returned and do some more calculation, lets say [Total] + 100 AS [Summed]
How do i access the subquery value in my outer query ? I dont want to execute the subquery again and again, want to reuse the value it returned the 1st time