Grouping a field with slightly simular names in SQL

  • I need to be able to group the customer field into a common value. The most common name would be BCI. and T-Mobile. I want to add a column for just the common value This is just one example of field values in the table. What is the best approach to accomplish this?

    Thanks

    Customer

    BCI (OK)

    BCI Communicatinss, Inc. (TX)

    BCI Communications

    BCI Communications (CA- Fairfield)

    BCI Communications (CA-- Chino)

    BCI Communications (CA-SD)

    BCI Communications (MD)

    BCI Communications (New England)

    BCI Communications (NV)

    BCI Communications AZ

    BCI Communications, Inc.

    BCI Communications, Inc. (CA)

    BCI Communications, Inc. (FL)

    BCI Communications, Inc. (NJ)

    Customer

    T-Mobile

    T-Mobile (AL-Birmingham)

    T-Mobile (AL-Mobile)

    T-Mobile (ATL)

    T-Mobile (AZ-Phoenix)

    T-Mobile (AZ-Tempe)

    T-Mobile (CA -Arroyo Grande)

    T-Mobile (CA-Concord)

    T-Mobile (CA-Irvine)

    T-Mobile (CA-Sacramento)

    T-Mobile (CA-Santa Ana)

    T-Mobile (CA-Simi Valley)

    T-Mobile (CO-Denver)

    T-Mobile (Corpus, TX)

    T-Mobile (CT-Bloomfield)

    T-Mobile (CT-Stanford)

    T-Mobile (DC-Washington)

    T-Mobile (Edina, MN)

    T-Mobile (FL- Sunrise)

    T-Mobile (FL-Jacksonville)

    T-Mobile (FL-Plantation)

    T-Mobile (FL-Tampa)

    T-Mobile (GA-Atlanta)

    T-Mobile (GA-Lawrenceville)

    T-Mobile (IL-Chicago)

    T-Mobile (IN-Indianapolis)

    T-mobile (KS)

    T-Mobile (Las Vegas-NV)

    T-Mobile (MA)

    T-Mobile (MD Hanover)

    T-Mobile (MD-Beltsville)

    T-Mobile (MD-Columbia)

    T-Mobile (MI-Livonia)

    T-Mobile (MI-Rockford)

    T-Mobile (MN-Cambridge)

    T-Mobile (MO-St. Louis)

    T-Mobile (NH-Northwood)

    T-Mobile (NJ-Jackson)

    T-Mobile (NJ-Parsippany)

    T-Mobile (NJ-Toms River)

    T-Mobile (NY Purchase)

    T-Mobile (NY)

    T-Mobile (NY-Bohemia)

    T-Mobile (NY-Flushing)

    T-Mobile (NY-Great River1)

    T-Mobile (NY-Latham)

    T-Mobile (NY-Latham1)

    T-Mobile (NY-Liverpool)

    T-Mobile (NY-Rochester)

    T-Mobile (NY-Rockville Centre)

    T-Mobile (OK)

    T-Mobile (Ontario, CA)

    T-mobile (OR)

    T-Mobile (PA - Pittsburgh)

    T-Mobile (PA)

    T-Mobile (PA-Bensalem)

    T-Mobile (PA-Philadelphia)

    T-Mobile (Purchase, NY)

    T-Mobile (RI-Providence)

    T-Mobile (Rockville Centre, NY)

    T-Mobile (San Diego, CA)

    T-Mobile (SC)

    T-Mobile (SE)

    T-Mobile (TN)

    T-Mobile (TN- Smyrna)

    T-mobile (TN-Nashville)

    T-Mobile (TX)

    T-Mobile (TX- Houston)

    T-Mobile (TX-Austin)

    T-Mobile (TX-Cordova)

    T-Mobile (TX-Dallas)

    T-Mobile (TX-El Paso)

    T-Mobile (UT)

    T-Mobile (VA)

    T-Mobile (WA- Maryville)

    T-Mobile (WA-Bellvue)

    T-Mobile (WA-Bothell)

    T-Mobile (WA-Newport News)

    T-Mobile (Wayne, NJ)

    T-Mobile -- Pittsburgh, PA

    T-Mobile Communications (OH)

    T-Mobile USA

    T-Mobile USA (Birmingham)

    T-Mobile USA, Hawaii

    T-Mobile USA, Inc.

    T-Mobile USA, Inc. (CA- San Diego)

    T-Mobile USA/Cook Inlet VS PCS

  • I don't believe there's a good way to do this. For the two instances you've shown, folks might be quick to say "Substring up to the first space". That will crash an burn for companies the use one of the 4 points of the compass or the name of the State they're in in the first word of their name.

    The "best" way might be to do the substring thing to get 80 or 90% of the problem solved but only if it's followed by human review to handle the exceptions.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • That's what I was thinking also. I'll let the cleint decide. Maybe I can add a field to the table and update it manually, then make the field a 'required" field so they will have to enter/select a "Parent" company going forward.

    Thanks for your input!!!

  • You bet. Thank you for the feedback.

    It would be interesting to find out what the client settles on. If you get a chance, please post back. I'm always interested on what the "human element" decides.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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