Retrieve First Name and Last Name

  • I have a table which has a column called Name, which contains the name of our vendors. The data format in this column is lastname, firstName. For example, Smith, John or Lee, Mathew.

    How can I split out the last name and first name separately?

    Thanks,

  • QQ-485619 (3/16/2012)


    I have a table which has a column called Name, which contains the name of our vendors. The data format in this column is lastname, firstName. For example, Smith, John or Lee, Mathew.

    How can I split out the last name and first name separately?

    Thanks,

    if every field has a comma, something like this would work...it's simply doing substrings based ont eh charindex of the comma.

    SELECT

    substring([FULLNAME],1,CHARINDEX(',',[FULLNAME]) -1) AS LASTNAME,

    substring([FULLNAME], CHARINDEX(',',[FULLNAME]) + 1,250) AS FIRSTNAME

    FROM SOMETABLE

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • CELKO (3/17/2012)


    First you need to read a book on basic data modeling;

    "name" is an attribute property, which means your column should have been "vendor_name" instead.

    it really sounds like the OP inherited the problem and is trying to resolve it. what happens then joe? what if the OP is reading the book and looking at the inherited database and thinking how he can fix the "Problem".


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply