---
title: "How to split the full name into FirstName and LastName in SQL server?"  
description: "How to split the full name into FirstName and LastName in SQL server?"  
author: "Ashutosh Patel"  
published: 2024-10-15  
updated: 2024-10-15  
canonical: https://www.mindstick.com/interview/33973/how-to-split-the-full-name-into-firstname-and-lastname-in-sql-server  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# How to split the full name into FirstName and LastName in SQL server?

To split a `FullName` into `FirstName` and `LastName` in SQL Server, you can use string functions like CHARINDEX, LEFT and RIGHT. Here is an example of how you can do this,

Assuming you have an SQL table `Employees` with a column `EmpName` that contains the name in the format of “FirstName and LastName”,

Here is the SQL Query to split the full name into first name and lastname

```plaintext
SELECT EmpName, LEFT(EmpName, CHARINDEX(' ', EmpName) - 1) AS FirstName,
   RIGHT(EmpName, LEN(EmpName) - CHARINDEX(' ', EmpName)) AS LastName
FROM Employees
```

## Example-

![How to split the full name into FirstName and LastName in SQL server?](https://www.mindstick.com/interviewquestion/f08af10a-13d4-4d62-8953-e939437171f5/images/7fe28d8f-cbe1-465b-b922-e3e6a9eeb2ea.png)

## Answers

### Answer by Ashutosh Patel

To split a `FullName` into `FirstName` and `LastName` in SQL Server, you can use string functions like CHARINDEX, LEFT and RIGHT. Here is an example of how you can do this,

Assuming you have an SQL table `Employees` with a column `EmpName` that contains the name in the format of “FirstName and LastName”,

Here is the SQL Query to split the full name into first name and lastname

```plaintext
SELECT EmpName, LEFT(EmpName, CHARINDEX(' ', EmpName) - 1) AS FirstName,
   RIGHT(EmpName, LEN(EmpName) - CHARINDEX(' ', EmpName)) AS LastName
FROM Employees
```

## Example-

![How to split the full name into FirstName and LastName in SQL server?](https://www.mindstick.com/interviewquestion/f08af10a-13d4-4d62-8953-e939437171f5/images/7fe28d8f-cbe1-465b-b922-e3e6a9eeb2ea.png)


---

Original Source: https://www.mindstick.com/interview/33973/how-to-split-the-full-name-into-firstname-and-lastname-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
