Find the lastName in SQL table

I have one table where I want to find out the last name from full Name. For Example-

Ramesh Kumar Singh

Mahesh Pratam Thakur

Dheeraj Mani Tripathi

Our answer should be following in the result-

Singh

Thakur

Tripathi

  Devbrat Tripathi

Hi,

i believe below is the correct answer.

SELECT SUBSTRING(fullname, 1, CHARINDEX(' ', fullname) - 1) AS Firstname,     
       SUBSTRING(fullname,
                 CHARINDEX(' ', fullname) + 1,
                 LEN(fullname) - CHARINDEX(' ', fullname)) AS Lastname
FROM yourTable                

  Rakesh Sharma       23 Sep 2018       1       0     

Post Your Answers:

Please use the CODE HIGHLIGHT Button to format/highlight your codes if any