Hi Wonder if someone can help me with this query. I have a data set within which I have two columns. Column A/Column B; lets call it Table UpdateData.
There are also two Access tables with standing data that are mapping tables for these codes. One table is pre-update codes (oldCodes) and the other is post-system update codes (NewCode). In my data set Column A has pre-update codes and column B has post-update codes. My idea was to combine these two Access tables new and old codes into one table in SQL Server (2005) like this To Create Table combinedCodes:
Oldcode display
===== =======
RTYX45 No
GHYUN6 No
BYUER5 Yes
Newcode display
===== =======
VUJNG6 Yes
LERWS8 No
XCRYU7 Yes
code display
===== =======
RTYX45 No
GHYUN6 No
BYUER5 Yes
VUJNG6 Yes
LERWS8 No
XCRYU7 Yes
Note this is only an example of data and there is a lot more rows than is displayed.
So if I join updateData and Combined codes how do I set it so that one field (display) can show the match from either column A/B (or not). When I joined on only one column lets say Column A with left join to my updateData table from combinedCodes table I got the correct data in my combinedCodes display field and nulls for the ones that didn't match.
But then I introduced another join from Column B using left join to my UpdateData table from CombinedCodes and the combinedCodes display showed Old Codes where before nulls were, which I would want, but also showed old codes where before the new codes were used. I was getting a bit mixed up with what was actually happening so this might not be 100% right however when comparing each query result with individual join the query results with the joins to column A and Column B was different although same count of data when adding up individual count from separate queries.
select c.Fields
--,f.Display
,pt.Display
from UpdateData c
INNER JOIN PRE_CODES pt
ON c.columnA = pt.code -- only for pre-codes
--INNER JOIN POST_CODES f
--ON c.columnB = f.code
The join and field commented out are for the post-codes and the other is for pre-codes. If i include left outer join to show nulls for post-codes then introduce 2nd join and f.display plus left join for field it doesn't show the same results as if I run each individually and combine them.
this kind of join is going beyond my understanding of joins and I do not know exactly what I should do here so over to any of you who can help me with this
Thanks
Andrew