T-SQL substring - separating first and last name

前端 未结 11 1741
南方客
南方客 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 06:07

    Assuming the FirstName is all of the characters up to the first space:

    SELECT
      SUBSTRING(username, 1, CHARINDEX(' ', username) - 1) AS FirstName,
      SUBSTRING(username, CHARINDEX(' ', username) + 1, LEN(username)) AS LastName
    FROM
      whereever
    

提交回复
热议问题