0

I am having single comma separated row of column as mentioned below and I need to split it into multiple rows if it exceeds the specified length

+-------------------+--------------------------------+-----------------+
      ID                          Name                     Length_Name 
+-------------------+--------------------------------+-----------------+
      1                David,John,James,Mary,Bryan            27
      2                Mike,Boucher,Pollard                   20
+-------------------+--------------------------------+-----------------+

Here suppose the Name column value's crosses the length of 12 it needs to mention like as below

+-------------------+--------------------------------+-----------------+
      ID                          Name                     Length_Name 
+-------------------+--------------------------------+-----------------+
      1                      David,John                      10
      1                      James,Mary                      10
      1                      Bryan                           5
      2                      Mike,Boucher                    12
      2                      Pollard                         7
--------------------+--------------------------------+-----------------+

Please, if anyone knows solution, kindly comment it.

Ergi Nushi
  • 837
  • 1
  • 6
  • 17
  • 2
    Fix your data model! Don't store multiple names in a comma-delimited string. – Gordon Linoff Nov 20 '19 at 12:16
  • Hi, in this context the data model looks wrong to me too, if all names in one row should be related in any way, use a second table and connect them by a key. Sure, there could be a way to cover your question direct, but i will guess it leads to other problems later! – sebkrueger Nov 20 '19 at 12:19
  • Tag says MySql, title says SQL Server. These are two different products... – Zohar Peled Nov 20 '19 at 13:02

0 Answers0