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
 General SQL Server Forums
 New to SQL Server Programming
 SUM Of Results

Author  Topic 

LacOniC
Starting Member

29 Posts

Posted - 2008-10-10 : 03:20:59
Table A
TableAID (int)

Table B
TableBID (int) TableAID (int) Hours (int)

Table A and B has a relation on TableAID. Table B contain multiple rows for same TableAID. I want to get SUM of hours for an TableA record from TableB. For example:

SELECT Hours FROM TableB B
JOIN TableA A ON A.TableAID = B.TableAID
WHERE TableAID = 1

Brings
1
3
4

How can i get 8 (sum of them) with one select?

Jason100
Starting Member

34 Posts

Posted - 2008-10-10 : 03:24:52
SELECT A.TableAID ,Sum(Hours) FROM TableB B
JOIN TableA A ON A.TableAID = B.TableAID
WHERE TableAID = 1
group by A.TableAID
Go to Top of Page

LacOniC
Starting Member

29 Posts

Posted - 2008-10-10 : 04:32:55
quote:
Originally posted by Jason100

SELECT A.TableAID ,Sum(Hours) FROM TableB B
JOIN TableA A ON A.TableAID = B.TableAID
WHERE TableAID = 1
group by A.TableAID



Thank you.
Go to Top of Page
   

- Advertisement -