How to split a comma-separated value to columns

后端 未结 30 3958
刺人心
刺人心 2020-11-21 04:38

I have a table like this

Value   String
-------------------
1       Cleo, Smith

I want to separate the comma delimited string into two colu

30条回答
  •  说谎
    说谎 (楼主)
    2020-11-21 04:49

    I found that using PARSENAME as above caused any name with a period to get nulled.

    So if there was an initial or a title in the name followed by a dot they return NULL.

    I found this worked for me:

    SELECT 
    REPLACE(SUBSTRING(FullName, 1,CHARINDEX(',', FullName)), ',','') as Name,
    REPLACE(SUBSTRING(FullName, CHARINDEX(',', FullName), LEN(FullName)), ',', '') as Surname
    FROM Table1
    

提交回复
热议问题