Question : How do you sum individual elements within one account in TSQL

I am trying to total by account, the expenses & income per account. There are multiples of both the income & the expenses per account. I am struggling with this as am still learning SQL and thought that someone else likely has already addressed this? I sure would appreciate the help!

I know that this SQL server code is not correct but it at least gives a bit clearer picture of what I am attempting to do.

IF(SELECT(OBJECT_ID('TEMPDB..#Total'))) IS NOT NULL DROP TABLE #Total

declare @Expenses decimal(13,2), @income decimal(13,2)

set @expenses = sum(EXP_CHILD_CARE_AMOUNT) + sum(EXP_FOOD_AMOUNT) + sum(EXP_LIFE_INSURANCE_AMOUNT) + sum(EXP_TRANSPORTATION_AMOUNT) + sum(EXP_TUITION_AMOUNT) + sum(EXP_USER_2_AMOUNT) + sum(EXP_USER_3_AMOUNT) + sum(EXP_UTILITIES_AMOUNT)

set @income = (sum(NET_PAY_AMOUNT) + sum(OTHER_INCOME_AMOUNT)

SELECT F.LOAN_NUMBER, @Income, @Expenses

INTO #Total FROM OPENQUERY(SvrLink, '

SELECT F.Account, @Income, @Expenses

FROM finances F inner join account a on(a.Account = f.Account) where a.balance > 0

FETCH ONLY WITH UR ')

Answer : How do you sum individual elements within one account in TSQL

Something like this:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
SELECT  F.Account,
        SUM(NET_PAY_AMOUNT) + SUM(OTHER_INCOME_AMOUNT) Income,
        SUM(EXP_CHILD_CARE_AMOUNT) + SUM(EXP_FOOD_AMOUNT) + 
        SUM(EXP_LIFE_INSURANCE_AMOUNT) + SUM(EXP_TRANSPORTATION_AMOUNT) + 
        SUM(EXP_TUITION_AMOUNT) + SUM(EXP_USER_2_AMOUNT) + 
        SUM(EXP_USER_3_AMOUNT) + SUM(EXP_UTILITIES_AMOUNT) Expenses
FROM    finances F
        INNER JOIN account a ON f.Account = a.Account
WHERE   a.balance > 0
GROUP BY F.Account
Random Solutions  
 
programming4us programming4us