Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pull sums from 2 tables
Message
From
15/10/2007 12:53:03
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01261037
Message ID:
01261064
Views:
13
It works GREAT Sergey, thanks! :o) I'm using it in development only (for checking amounts and looking for discrepancies.


>Tracy,
>
>Try
>
>SELECT id, sum(t1.owed) AS owed, sum(t1.paid) AS paid,
>		(SELECT SUM(tpaid) FROM table2 t2 WHERE t1.id = td2.id)  AS tpaid
>	GROUP BY id
>
>>I have 2 sql server 2005 tables:
>>
>>table1
>>
>>id
>>owed
>>paid
>>
>>table2
>>
>>id
>>tpaid
>>
>>I want to pull:
>>
>> sum(table1.owed) as owed, sum(table1.paid) as paid, sum(table2.tpaid) as tpaid
>> where table1.id = table2.id
>>
>>There are multiple records for each id in both tables. It seems simple, but I just can't seem to get it right. Any ideas?
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform