Hi, I have a table:
I would like to merge Col1, Col2, Col3 into Col4 in alphabetical order separated with a comma to end up with:
Col4:
ANDERSON, JOHNSON, SMITH
JOHNSON ALAN, JOHNSON BILL, JOHNSON JACOB
ANTON, BUNDY, KIMBER
COMERN, COOLER, KYLER
Can anyone think of how I can do this?
Thanks!
Brian
Code:
create table #temp (col1 varchar(25), col2 varchar(25), col3 varchar(25), col4 varchar(25), col5 varchar(200))
go
insert into #temp (col1, col2, col3) values ('SMITH', 'JOHNSON', 'ANDERSON')
insert into #temp (col1, col2, col3) values ('JOHNSON BILL', 'JOHNSON ALAN', 'JOHNSON JACOB')
insert into #temp (col1, col2, col3) values ('KIMBER', 'ANTON', 'BUNDY')
insert into #temp (col1, col2, col3) values ('COOLER', 'KYLER', 'COMERN')
I would like to merge Col1, Col2, Col3 into Col4 in alphabetical order separated with a comma to end up with:
Col4:
ANDERSON, JOHNSON, SMITH
JOHNSON ALAN, JOHNSON BILL, JOHNSON JACOB
ANTON, BUNDY, KIMBER
COMERN, COOLER, KYLER
Can anyone think of how I can do this?
Thanks!
Brian