Selecting Field that contains data from another field

  • Okay - here is the problem I have.

    We have a stock code table with a description field and a brand field - when the data was entered, some of the records were entered with the brand field in the description field.

    ie.

    Code Description Brand

    ABC1 BLANK DVD SONY

    ABC2 SONY BLANK DVD SONY

    what I need to do is identify where the Brand is in the Description field ...

    I have tried ;

    select * from Table

    where Description Like Brand

    not very successful.

    ________________________________________________________________________________________________
    Regards
    Steve
    SQL 2008 DBA/DBD - MCTS/MCITP

    Please don't trust me, test the solutions I give you before using them.

  • SteveEClarke (5/28/2015)


    Okay - here is the problem I have.

    We have a stock code table with a description field and a brand field - when the data was entered, some of the records were entered with the brand field in the description field.

    ie.

    Code Description Brand

    ABC1 BLANK DVD SONY

    ABC2 SONY BLANK DVD SONY

    what I need to do is identify where the Brand is in the Description field ...

    I have tried ;

    select * from Table

    where Description Like Brand

    not very successful.

    You're missing the wildcard characters on the front and back of the Brand you want to search for in Description.

    select *

    from Table

    where Description Like '%' + Brand + '%';

    This query is going to be slow because the leading % will prevent it from using an index, but it should find your offending rows. I'd suggest that you have the front end updated to not allow the bad data in there in the first place.

  • Thanks for your help.

    Unfortunately the data is from old data - so this is the cleansing routines.

    ________________________________________________________________________________________________
    Regards
    Steve
    SQL 2008 DBA/DBD - MCTS/MCITP

    Please don't trust me, test the solutions I give you before using them.

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

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