Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Row Wise Sum

Author  Topic 

khalid.mushtaq
Starting Member

2 Posts

Posted - 2008-12-03 : 01:07:25
I actually want to know how to sum up data row wise and insert it into the same table.
eg
Name|BASIC|Hra|TA|Total

asd |2300 |200|20|NULL
zxc |2200 |100}30|NULL

I want sum of all rows which should be stored in "Total" column

Thanks in advance

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-12-03 : 01:17:10
select BASIC+Hra+TA from yourtable
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-03 : 01:20:22
if columns are nullable use COALESCE(col,0) instead of simply col
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-03 : 01:51:38
[code]UPDATE Table
SET Total=COALESCE(BASIC,0)+COALESCE(Hra,0)+COALESCE(TA ,0)[/code]
Go to Top of Page
   

- Advertisement -