Avatar of kbios
kbios
 asked on

SQL Query: How to split one field into two

I have a simple query that is retrieving a name field from a table. There is NOT an individual first name and last name field; the table value is firstname;lastname. During the SELECT how can I split firstname;lastname into two columns?
Microsoft SQL Server 2008

Avatar of undefined
Last Comment
kbios

8/22/2022 - Mon
dsacker

SELECT  LEFT(name, CHARINDEX(';', name) - 1)            AS FirstName,
        SUBSTRING(name, CHARINDEX(';', name) + 1, 80)   AS LastName
FROM    YourTable

Open in new window

This makes a hard assumption that there will always be that semicolon there.
ASKER CERTIFIED SOLUTION
Leo Torres

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
kbios

ASKER
Thanks. It worked GREAT!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23