I am working with a large database that link client information using two columns: co_code and i_code. co_code includes the new ID's for our clients as we transfer data over from an older system. i_code is the prior client ID with information still relevant in the datasystem that I need to pull for a report I am creating.
The i_code column, however, sometimes has multiple ID's which fall under the same new co_code ID. For instance:
+---------+---------------------------+
| co_code | i_code |
+---------+---------------------------|
| 1 | 768 |
| 2 | 134,4546,234 |
| 3 | 2354 |
| 4 | 3454,65465 |
| 5 | 432,76878,3543,43546,3435 |
| 6 | 535,65765 |
| 7 | 6345 |
| 8 | 1675 |
| 9 | 256 |
| 10 | 3768,6585,4654 |
+---------+---------------------------+
I have tried a series of different string split variations. My most recent is:
select co_code, i_Code from Prod_Detail where i_code in (select i_Code from string_split('i_code',','))
So far, I have not had any luck with splitting up the strings unless I do each individual row separately. As I am working with thousands of rows, this is not feasible within a small time frame.
Ideally, the output would look like the following:
+---------+--------+
| co_code | i_code |
+---------+--------+
| 1 | 768 |
| 2 | 134 |
| 2 | 4546 |
| 2 | 234 |
| 3 | 2354 |
| 4 | 3454 |
| 4 | 65465 |
| 5 | 432 |
| 5 | 76878 |
| 5 | 3543 |
| 5 | 43546 |
| 5 | 3435 |
| 6 | 535 |
| 6 | 65765 |
| 7 | 6345 |
| 8 | 1675 |
| 9 | 256 |
| 10 | 3768 |
| 10 | 6585 |
| 10 | 4654 |
+---------+--------+