Tuesday 26 May 2015

MS SQL - How to Calculate Sum of Multiple Columns in one row

Watch this example on YouTube:



Here is my table:



I want to know what is total of bonus, salary and gambling for each user
The following query will provide me with this info:

Select CustomerName,
 (Select Sum(Earnings)
  From (Values (Bonus), (Salary), (Gambling)) As tblSum(Earnings))
From Table3




2 comments:

  1. Better Way...

    Select CustomerName, (Bonus + Salary + Gambling ) as Earnings
    From Table3

    ReplyDelete