T-SQL substring - separating first and last name

前端 未结 11 1744
南方客
南方客 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条回答
  •  独厮守ぢ
    2020-11-30 05:57

    The easiest way I can find to do it is:

    SELECT 
      SUBSTRING(FullName, 1, CHARINDEX(' ', FullName) - 1) AS FirstName,
      REVERSE(SUBSTRING(REVERSE(FullName), 1, CHARINDEX(' ', REVERSE(FullName)) - 1)) AS LastName
    FROM
      [PERSON_TABLE]
    

提交回复
热议问题