Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pull sums from 2 tables
Message
From
15/10/2007 14:40:26
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01261037
Message ID:
01261095
Views:
16
There is a master id table, but there is always at least one record for each id in each table. When an initial record is added to table1 by subid owed field, one is added to table2. There could be numerous records in table2 to equal the value in the single record paid field in table1 for each subid.

For instance:
link id = 1

Table1:

Id             owed      paid  subid
1    rcd1    175.00    125.00     22
1    rcd2     50.00      0.00     23

Table2:

Id            tpaid            subid
1    rcd1   -175.00               22  && matches rcd1 field owed in table1
1    rcd2     50.00               22  && rcd2+rc3+rcd4 of table2 = table1 rcd1 field paid
1    rcd3     50.00               22
1    rcd4     25.00               22
1    rcd5    -50.00               23  && matches rcd2 field owed in table1
If I match up tpaid in table2 to paid in table1 for > 0 it should equal
If I match up tpaid in table2 to owed in table2 for < 0 in table2 and > 0 in table1 it should equal
summing tpaid for id = 1 in table2 should equal the sum of owed-paid in table1
.·*´¨)
.·`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