Ways of Extracting the Last Name from a Fully Qualified Name using Sql Server.

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 399
1st way:-
DECLARE @FullName VARCHAR(100) = 'Vishal Kumar';
SELECT REVERSE(LEFT(REVERSE(@FullName),
CHARINDEX(' ',REVERSE(@FullName)) - 1)) AS [Last_Name]

2nd way:-
SELECT RIGHT(@FullName,
CHARINDEX(' ',REVERSE(@FullName)) - 1) AS [Last_Name]

Output:-
Kumar

Comments or Responses

Login to post response