Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum newfield (variable) from select statement

Status
Not open for further replies.

james0816

Programmer
Jan 9, 2003
295
US
I know this can be done but unfortunately, I cannot remember how to code it.

If i have the following select statement

select a, b, c, (case when a = 2 then a else b + c) as newfield

from testtbl

where a <9

this will result in quite a few records. What I want to do is a sum statement to get the sum of newfield.

can someone assist?

thx
 
Code:
select sum(newfield) as total_newfield
  from (
       select a
            , b
            , c
            , case when a = 2 
                   then a 
                   else b + c end ) as newfield
         from testtbl
        where a < 9
        ) as mydata

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top