Hi all,
Hoping for a little help. I'm trying to create a query which can look at variances between two sources. I've tried a few things but they all require multiple queries which does work but wondering more out of curiosity, if it is possible to create the desired result with simply one query. Of course everything works fine if there is only one security but since either A or B can contain records for which there is no match in the other table this causes issues. Joining the tables in most of the manners I can think of result in a ambiguous join errors which I suspect is due to the fact that the query has to capture everything in the reference table but needs to join on the security in order to stop the query from comparing every record in A to those in B. Attempting to add a new table which has all the Securities also causes an ambiguous join error.
Inputs
Table A(Source A)
Field1 - Fund
Field2 - Security
Field3 - Amt
Fund Security Amt
A S1 100
B S1 100
C S2 150
Table B(Source B)
Field1 - Account
Field2 - Security
Field4 - Amt
Account Security Amt
1 S1 100
2 S1 50
3 S2 50
1 S2 50
4 S2 50
Table C(Reference)
Field1 - Fund
Field2 - Account
Fund Account
A 1
B 2
C 3
D 4
Expected Results
Fund A / Account 1
Security S1 no variance
Security S2 variance of 50 (tblB long 50)
Fund B / Account 2
Security S1 Variance 50 (tblB short 50)
Fund C / Account 3
Security S2 Variance 100 (tblB short 100)
Fund D / Account 4
Security S2 Variance 50 (tblB long 50)