I have two tables A and B;
Table A:
Cust_ID, Col_A, Col_B
1001, 1, 2
1002, 3, 4
1003, 2, 1
1004, 4, 3
Table B:
Col_A_Weight, Col_B_Weight
0.1111111, 0.22222
What i’m trying to do is create a new Table C using T-SQL, where
Output = Col_A*Col_A_Weight + Col_B*Col_B_Weight
Table C:
Cust_ID, Output
1001, 1*0.1111111 + 2*0.22222
1002, 3*0.1111111 + 4*0.22222
1003, 2*0.1111111 + 1*0.22222
1004, 4*0.1111111 + 3*0.22222
So that final Table C is
Cust_ID Output
1001, 0.5555511
1002, 1.2222133
1003, 0.4444422
1004, 1.1111044
Given that there are 200 Col_A, Col_B, Col_C, Col_D etc and corresponding weight columns, how to use a clever join so that the columns are referenced dynamically (given that they correspond across both tables). Since Table B has no Cust_ID field, this makes it a little more trickier.
How can this be done?
1 Answer