I have two tables: table A holds master product data, and table B holds children product data. I would like to update table A to hold the same value of the identical columns in table B when it only has one distinct value. If the distinct count is great than one, I would like to concatenate the columns with a comma. The tables have the same columns except the key column name.
Is it possible to write dynamic SQL that will match up all the columns and handle the merge / concatenation?
Example below:
Table A
ID | color | Location ____| ______|_____________ 1 | | 2 | | 3 | | 4 | |
Table B
child_ID | parent_id | Color | Location __________|___________|________|_________ 1 | 1 | white | house 2 | 2 | red | garage 3 | 2 | white | garage 4 | 3 | blue | house
Table A will look like:
ID | color | Location ____| ___________|_____________ 1 | white | house 2 | red, white | garage 3 | white | house