I have two tables – Table A and Table B
Table A
Value Value2 Number
------- ------ ------
AA 1 138
AB 2 234
AC 3 897
BA 4 274
BB 5 391
CA 4 994
CA 5 287
Table B
Value Value2 Number
------- ------ ------
AA 1 458
AB 2 434
AC 3 557
CA 4 564
I am joining Table A and Table B with respect to Value and Value2 column.
Select * from Table A TA
join Table B TB
on TA.Value = TB.Value and TA.Value2 = TB.Value2
Table A and Table B does not have all the matching value , for example value column of Table A have BA and BB which is not matching in Table B value column , So I need to replace BA and BB with CA and join it.
I started writing the script but wrote a long script.
I used except
to get all the value column from TABLE A not matching TABLE B , and put this into a temp table. Then loop and replace the BA / BB column with CA column. But I think there should be a easy steps than this which I struggle to find.
Any suggestions please.