How to find sum of multiple columns in a table in SQL Server 2005?

后端 未结 8 1974
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 17:13

I have a table Emp which has these rows:

Emp_cd | Val1  | Val2  | Val3  | Total
-------+-------+-------+-------+-------
 1     | 1.23  | 2.23  |         


        
相关标签:
8条回答
  • 2020-12-04 17:57

    Hi You can use a simple query,

    select emp_cd, val1, val2, val3,
    (val1+val2+val3) as total 
    from emp;
    

    In case you need to insert a new row,

    insert into emp select emp_cd, val1, val2, val3,
    (val1+val2+val3) as total 
    from emp;
    

    In order to update,

    update emp set total = val1+val2+val3;
    

    This will update for all comumns

    0 讨论(0)
  • 2020-12-04 18:05

    Try this:

    select sum(num_tax_amount+num_total_amount) from table_name;
    
    0 讨论(0)
提交回复
热议问题