Let's say I have a table named Sample with the following columns:
ID - int identity(1,1)
Codes - varchar(50)
Code1 - varchar(10)
Code2 - varchar(10)
Code3 - varchar(10)
Let's say the table has the following data:
ID, Codes, Code1, Code2, Code3
1, A01^A02^A03, null, null, null
2, B01^B02^B03, null, null, null
3, C01^C02, null, null, null
4, D01, null, null, null
Notice that the Codes column is a list of values delimited by a caret (^). Assuming that there are a maximum of three values in the Codes column, I would like to update the Code1, Code2, and Code3 columns with these values so that the data in the table becomes:
ID, Codes, Code1, Code2, Code3
1, A01^A02^A03, A01, A02, A03
2, B01^B02^B03, B01, B02, B03
3, C01^C02, C01, C02, null
4, D01, D01, null, null
How do I do this? Please show your transact SQL code solution.
Thanks in advance!