T-SQL substring - separating first and last name

前端 未结 11 1762
南方客
南方客 2020-11-30 05:50

I have a column which has FirstName and LastName together. I\'m writing a report to separate the FirstName And LastName. How do I get the FirstName and LastName separated in

11条回答
  •  猫巷女王i
    2020-11-30 06:04

    You could do this if firstname and surname are separated by space:

    SELECT SUBSTRING(FirstAndSurnameCol, 0, CHARINDEX(' ', FirstAndSurnameCol)) Firstname,
    SUBSTRING(FirstAndSurnameCol, CHARINDEX(' ', FirstAndSurnameCol)+1, LEN(FirstAndSurnameCol)) Surname FROM ...
    

提交回复
热议问题