I have data in the form of two keys that need to be combined based on a commonality between the two. In other words, I want to create a long string of combined pairs for every instance that it is shared. Please refer to the table below for reference and examples:
What my data looks like:
KEY1 | KEY2
===========
1 A
1 B
1 C
2 A
2 F
3 D
3 G
3 H
How I want to create new columns:
KEY1 | KEY2 | NEW KEY1 | NEW KEY2
=================================
1 A 1_A_B_C A_1_2
1 B 1_A_B_C B_1
1 C 1_A_B_C C_1
2 A 2_A_F A_1_2
2 F 2_A_F F_2
3 D 3_D_G_H D_3
3 G 3_D_G_H G_3
3 H 3_D_G_H H_3
Note that in the example where KEY1 = 1, the NEW KEY1 becomes a string of every instance of KEY2 associated with KEY1. The same would be done then for KEY2. Please note that I am using SQL Server 2008.
Thank you.