How to split a column of text into multiple columns in SQL Server

Опубликовано: 02 Март 2026
на канале: Select Distinct
12,395
42

#datacleaning #texttocolumn #sqlserver
Learn how to split full names into first and last name columns using SQL Server!

This quick tutorial walks you through using `CHARINDEX`, `SUBSTRING`, and `LEFT` functions to separate a single text column into multiple fields, perfect for cleaning up messy name data in SQL Server.

What you’ll learn:
How to split a full name column into first and last names
Practical use of `CHARINDEX`, `SUBSTRING`, and `LEN`
Real SQL examples with `CREATE TABLE` and `INSERT` statements
Tips for handling space positions in text fields

Ideal for:
Data analysts, SQL beginners, and anyone working with name parsing or text manipulation in SQL Server.

Code Snippet Used in This Video:

CREATE TABLE [dbo].[Names_Test] ([Full_Name] NOT NULL);
INSERT INTO Names_Test VALUES ('Ivan Smith'), ('Kenya Villareal'), ('Simeon Hancock'), ('Mercedes Vaughan'), ('Frank Smith'), ('Lee Mooney');

SELECT
Full_Name,
CHARINDEX(' ', Full_Name) AS [Space Position],
LEN(Full_Name) AS [Name Length],
LEFT(Full_Name, CHARINDEX(' ', Full_Name) - 1) AS [First Name],
SUBSTRING(Full_Name, CHARINDEX(' ', Full_Name) + 1, LEN(Full_Name)) AS [Last Name]
FROM Names_Test;

Read the full blog post:
https://www.selectdistinct.co.uk/2023...

Subscribe for more SQL tips, dashboard tutorials, and data strategy insights.

We simplify complex data tasks with modular clarity and branded visuals.

#SQLServer #SQLTutorial #DataCleaning #CHARINDEX #SUBSTRING #SplitColumn #SQLBeginners #PowerQuery #DataTransformation #selectdistinct


music by www.bensound.com