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 2000 Forums
 SQL Server Development (2000)
 Calculating Sum

Author  Topic 

skillile
Posting Yak Master

208 Posts

Posted - 2002-02-22 : 08:30:38
Even though the design is messy can this be done?

I have a table with mins & mins2 and I want to add the two fields from
multiple records. (I know it should be related by taskid in another table
but I didn't have that luxury, yet)

--create table #current
(taskid int, oid int, responsible varchar(20), responsible2 varchar(20),
mins int, mins2 int, billable int, billable2 int)

insert #current values(1,100, 'Melinda', NULL, 60, 0, 1,0)
insert #current values(1,100, NULL, 'Christie' , 0,3, 0,1)

select sum(mins) as total from #current where billable = 1 group by taskid
union all
select sum(mins2)as total from #current where billable2= 1 group by taskid

can we the total minutes billed. In this example it would be 63 but listed
in one row for a rs return.

thanks

slow down to move faster...

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-02-22 : 08:45:52
Why not:

SELECT Sum(mins + mins2) AS total
FROM #current
WHERE billable=1 OR billable2=1
GROUP BY taskid




Go to Top of Page
   

- Advertisement -