Link to home
Start Free TrialLog in
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?
Avatar of dsacker
dsacker
Flag of United States of America image

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
Avatar of Leo Torres
Leo Torres
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kbios
kbios

ASKER

Thanks. It worked GREAT!