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

后端 未结 8 1998
爱一瞬间的悲伤
爱一瞬间的悲伤 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:56

    use a trigges it will work:-

    ->CREATE TRIGGER trigger_name BEFORE INSERT ON table_name

    FOR EACH ROW SET NEW.column_name3 = NEW.column_name1 + NEW.column_name2;

    this will only work only when you will insert a row in table not when you will be updating your table for such a pupose create another trigger of different name and use UPDATE on the place of INSERT in the above syntax

提交回复
热议问题