0

I have an issue with converting a varchar column filled with id's (foreign keys) to another string with names, these names are linked in another table with their correlating id.

Data

 x-----x------------------------x
 | Id  | foreign Keys (varchar) |
 x-----x------------------------x
 |  1  |  1,2,3                 |
 |  2  |  2,3,4                 |
 |  3  |  4                     |  
 x-----x------------------------x 

Names

 x-----x-----------------x
 | Id  |  Names (varchar)|
 x-----x-----------------x
 |  1  |  Rick           |
 |  2  |  Steven         | 
 |  3  |  Charly         |
 |  4  |  Tom            | 
 x-----x-----------------x 

Basically I need the values in the table data to UPDATE to a varchar like 'Rick, Steven, Charly'.

I am working in SQL Server 2014, so I can't use the function STRING_SPLIT.

Help would be really appreciated

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    I don't suppose there's any chance you could just fix the Data table to be `Id INT, NameId INT` instead of storing comma separated values? – squillman Apr 11 '22 at 15:02
  • As sqillman says don't make a headache for yourself if you can help it. There are ways to do it but it's cleverer to do it simply, the way SQL is supposed to work. –  Apr 11 '22 at 15:44
  • Yeah the thing is the table where I need to insert those values into which are comma separated is bit more complicated. The column has more options for values. It is an sort of collective of different kind of values.(ints, datetimes, strings). So I really I need the answer to the approach described as above. – Sander_Pol Apr 11 '22 at 15:53
  • Build a string_split in SQL 2014: [String_Split SQL2014](https://stackoverflow.com/questions/55618878/function-string-split-in-sql-server-2014) or [String_Split SQL2012](https://stackoverflow.com/questions/46902892/string-split-in-sql-server-2012) – Johannes Krackowizer Apr 11 '22 at 18:09
  • Sounds like you need to really rethink your table design – Charlieface Apr 12 '22 at 18:36

0 Answers0