0

Split comma separated name (last, first)

The following example will return two columns (first name, last name) based on a single, concatenated, comma separated name.

table
------
name
------
Chin, Cheryl
Frank, Robert
SELECT
	RIGHT([name], LEN([name]) - CHARINDEX(',', [name]) - 1) AS [first],
	LEFT([name], CHARINDEX(',', [name])-1) AS [last]
FROM
	table
Result
first  last   
------ -----
Cheryl Chin
Robert Frank

Alternatively, you can use PARSENAME:

SELECT
	PARSENAME(REPLACE([Name], ', ', '.'), 1) AS [first],
	PARSENAME(REPLACE([Name], ', ', '.'), 2) AS [last]
FROM
	table

Norbert Krupa

Technical Consultant

Leave a Reply

Your email address will not be published.