Sum the fields in SELECT Statement

How I can make sum for 2 sums in SELECT statement as

SELECT Distinct E.fld_Employee_CODE, E.FROM_PERIOD, E.TO_PERIOD,

(SELECT Sum(I.ALW_DED_AMOUNT) 
FROM tbl_EmployeeMonthSalary AS I 
Where I.fld_Employee_CODE = E.fld_Employee_CODE and E.FROM_PERIOD = E.FROM_PERIOD and I.TO_PERIOD = E.TO_PERIOD
and I.ALW_DED_CODE = "666") As [Basic Salary],
(SELECT Sum(I.ALW_DED_AMOUNT) 
FROM tbl_EmployeeMonthSalary AS I 
Where I.fld_Employee_CODE = E.fld_Employee_CODE and E.FROM_PERIOD = E.FROM_PERIOD and I.TO_PERIOD = E.TO_PERIOD
and I.ALW_DED_CODE = "777") As [Accomadation],
(SELECT Sum(I.ALW_DED_AMOUNT) 
FROM tbl_EmployeeMonthSalary AS I 
Where I.fld_Employee_CODE = E.fld_Employee_CODE and E.FROM_PERIOD = E.FROM_PERIOD and I.TO_PERIOD = E.TO_PERIOD
and I.ALW_DED_CODE = "888") As [Electrisity],
(SELECT Sum(I.ALW_DED_AMOUNT) 
FROM tbl_EmployeeMonthSalary AS I 
Where I.fld_Employee_CODE = E.fld_Employee_CODE and E.FROM_PERIOD = E.FROM_PERIOD and I.TO_PERIOD = E.TO_PERIOD
and I.ALW_DED_CODE = "999") As [Water],
[Basic Salary]+[Accomadation]+[Electrisity]+[Water] As [Total Salary]

FROM tbl_EmployeeMonthSalary AS E 

Open in new window


In above example you can see
(SELECT Sum(I.ALW_DED_AMOUNT) 
FROM tbl_EmployeeMonthSalary AS I 
Where I.fld_Employee_CODE = E.fld_Employee_CODE and E.FROM_PERIOD = E.FROM_PERIOD and I.TO_PERIOD = E.TO_PERIOD
and I.ALW_DED_CODE = "666") As [Basic Salary],
(SELECT Sum(I.ALW_DED_AMOUNT) 
FROM tbl_EmployeeMonthSalary AS I 
Where I.fld_Employee_CODE = E.fld_Employee_CODE and E.FROM_PERIOD = E.FROM_PERIOD and I.TO_PERIOD = E.TO_PERIOD
and I.ALW_DED_CODE = "777") As [Accomadation],

Open in new window


I'm using MS Access

How I can sum the [Basic Salary] and [Accomadation] ?
egovernmentAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
Beyond just [Basic Salary]+[Accomadation] ?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dale FyeOwner, Developing Solutions LLCCommented:
Are you just trying to get the Basic Salary, Accomadation, Electrisity, Water, and Total Salary for each employee, time period combination?  If so, try:

SELECT E.fld_Employee_Code,
            E.From_Period,
            E.To_Period,
            Sum(iif(E.ASL_DED_CODe] = "666", E.ALW_DED_AMOUNT, 0))  As [Basic Salary],
            Sum(iif(E.ASL_DED_CODe] = "777", E.ALW_DED_AMOUNT, 0))  As [Accomadation],
            Sum(iif(E.ASL_DED_CODe] = "888", E.ALW_DED_AMOUNT, 0))  As [Electrisity],
            Sum(iif(E.ASL_DED_CODe] = "999", E.ALW_DED_AMOUNT, 0))  As [Water],
            SUM([Basic Salary]+[Accomadation]+[Electrisity]+[Water]) As [Total Salary]
FROM tbl_EmployeeMonthSalary AS E
GROUP BY SELECT E.fld_Employee_Code, E.From_Period, E.To_Period
0
Dale FyeOwner, Developing Solutions LLCCommented:
After you run your version (time it to see how long it takes), you might want to try my version.  Your version is going to take forever to run, compared to my recommendation.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.