Using SQL Server, I'm trying to split information shared in one column into three based on the number of IDs. Ideally I'd have distinct IDs at the end.
There can be from 1-3 rows per PersonID depending on the information in the contact column.
If a personID appears more than once I'd like to have the data split into two columns, one for phone and one for email.
I'd need to check that the data contained an "@" symbol for it to be put into the Email column, and the rest put into Phone or Alt Phone.
It's pretty hard to explain so if you need any more information please comment.
Hopefully the example below will help:
PersonID Name Contact
----------------------------------------
1 Chen 212747
1 Chen Chen@test.com
2 Pudge 18191
2 Pudge 18182222
2 Pudge Pudge@test.com
3 Riki Riki@test.com
3 Riki 19192
4 Lina 18424
I want to convert this into :
PersonID Name Phone Alt Phone Email
--------------------------------------------------------
1 Chen 212747 NULL Chen@test.com
2 Pudge 18191 18182222 Pudge@test.com
3 Riki 19192 NULL Riki@test.com
4 Lina 18424 NULL NULL