0

I have a column in SQL that has a name and various other items in it. I'm trying to figure out how to parse the name out and create new columns for it. I want to add two new columns and the new columns would then have first name and last name.

Example

APPLES-JST-JN-2022-07-22:BANANA:MELISSA:CUMBERBACH
1
  • Use SUBSTRING_INDEX() to extract parts of a delimited string. Commented Aug 5, 2022 at 22:13

1 Answer 1

1

Use SUBSTRING_INDEX() to extract parts of a string that use a delimiter to separate values.

ALTER TABLE yourTable ADD FirstName VARCHAR(100), ADD LastName VARCHAR(100);

UPDATE yourTable 
SET FirstName = SUBSTRING_INDEX(SUBSTRING_INDEX(yourColumn, ':', -2), ':', 1),
    LastName = SUBSTRING_INDEX(yourColumn, ':', -1);

Replace yourTable and yourColumn with the actual table and column names.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.