Guru Ji
asked on
SQL Query
Table 1
PrimaryOrderID, AlternativeOrderID
123 234
455 238
233 231
533 345
Table2
OrderDate, OrderID, Balance Owing
12/12/2000 231 $0.23
12/11/2000 238 $0.23
12/10/2000 232 $0.23
14/12/2000 455 $0.23
12/08/2000 234 $0.80
12/04/2000 123 $0.00
12/12/2000 345 $0.23
12/12/2000 533 $0.57
What I want is to
1. Find all records in Table2 where AlternativeOrderID from table1 has some balance owing matching orderid in table2.
2. Find all records in Table2 where AlternativeOrderID from table1 has some balance owing matching orderid in table2
In above result I want to see only those records where PrimaryOrderID exist in Table2
3. I want to update Table 2 by looking at Table 1 info such that any AlternativeOrderID balance owing in table 2 should add to PrimaryOrderID in table 2.
For example Alternative ID 345 has balance of $0.23 in Table 2 and and PrimaryOrderID of that is 533 with balance of 0.57
I want to update the table to that 0.23 cents adds to that 0.57 in table 2 so the result will be
OrderDate, OrderID, Balance Owing
12/12/2000 345 $0.23
12/12/2000 533 $0.80
Can someone help please
Thanks,
PrimaryOrderID, AlternativeOrderID
123 234
455 238
233 231
533 345
Table2
OrderDate, OrderID, Balance Owing
12/12/2000 231 $0.23
12/11/2000 238 $0.23
12/10/2000 232 $0.23
14/12/2000 455 $0.23
12/08/2000 234 $0.80
12/04/2000 123 $0.00
12/12/2000 345 $0.23
12/12/2000 533 $0.57
What I want is to
1. Find all records in Table2 where AlternativeOrderID from table1 has some balance owing matching orderid in table2.
2. Find all records in Table2 where AlternativeOrderID from table1 has some balance owing matching orderid in table2
In above result I want to see only those records where PrimaryOrderID exist in Table2
3. I want to update Table 2 by looking at Table 1 info such that any AlternativeOrderID balance owing in table 2 should add to PrimaryOrderID in table 2.
For example Alternative ID 345 has balance of $0.23 in Table 2 and and PrimaryOrderID of that is 533 with balance of 0.57
I want to update the table to that 0.23 cents adds to that 0.57 in table 2 so the result will be
OrderDate, OrderID, Balance Owing
12/12/2000 345 $0.23
12/12/2000 533 $0.80
Can someone help please
Thanks,
Is this an homework question?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.