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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum accross multiple columns

Status
Not open for further replies.

laquer09

MIS
Mar 14, 2003
10
I am trying to get the sum of multiple fields in a table. The query listed below will get the sum of each of the 2 fields (total_1 and total_2) in the query.

How can I get the sum for both columns in 1 field (e.g. sum_total)?
How can I continue to include additional fields?

SELECT Sum(Projects.[8-Est$-Pre2002]) AS total_1,
Sum(Projects.[8-2004$-OrigEst]) AS total_2
FROM Projects;

Thanks
 
Hi,

[tt]
SELECT Sum(P.[8-Est$-Pre2002]) AS total_1,
Sum(P.[8-2004$-OrigEst]) AS total_2, Sum(P.[8-Est$-Pre2002]+P.[8-2004$-OrigEst]) AS total_3
FROM Projects P;
[/tt]



Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Skip

Thanks for the help ... i've worked mostly with Oracle and I am always struggling with syntax in Access.

A follow up question out of curiosity: why wouldn't Access accept the following rendition of what you showed me?

SELECT Sum(P.[8-Est$-Pre2002]) AS total_1,
Sum(P.[8-2004$-OrigEst]) AS total_2,
Sum(total_1+total_2) AS total_3
FROM Projects P;
 
Don't think you can do that.

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
This worked syntactically, but the numbers aren't adding up right ... I just noticed that a few moments ago.

SELECT Sum(P.[8-Est$-Pre2002]) AS total_1,
Sum(P.[8-2004$-OrigEst]) AS total_2, Sum(P.[8-Est$-Pre2002]+P.[8-2004$-OrigEst]) AS total_3
FROM Projects P;

Yields the resutlts:
total_1: $76,096,706.00
total_2: $146,514,562.00
total_3: $101,562,904.00 (should be $222,611,268.00)

Please let me know if you have any suggestions

Thank you very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top