Searching a part of String in string Column

  • Hi,

    I require a little help on string query.

    I have two table ( Table A and Table B) each having employee column with string values.

    I want to search that does part of Table A.employee column is having matching value in Table B.employee column

    Table A. Employee

    -----------------

    Steve Smith

    John Davis

    Table B. Employee

    -----------------

    Steve Craig

    Peter Thomas

    I want to search if Employee having name "Steve" from table A is having matching value from TableB. Employee.

  • You didn't specify how get the parts but in your example it was the first written name until the first space. If this is the criteria that you need, then you can use the substring function combined with charindex function that searches for the first space in both tables. Notice that it will cause a table scan. One more thing – in my signature there is a link to an article that explains how to ask a question. It is much better to follow the directions on this article and write a small script with DDL that creates the tables and insert statement that insert data then just values that the tables should have. Writing such a script would help people that will show you a code example of how to do what you asked.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Double post, please post replies here.

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

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