• a20213 (4/19/2013)


    hello, i am trying to make a procedure that returns values if and only the query matches all words .. EX:

    declare @Names TABLE

    (

    name varchar(100)

    )

    DECLARE @Searchs TABLE

    (

    word varchar(100)

    )

    insert into @Searchs (word) select items from dbo.Split('John Andrews', ' ')

    insert into @Names values ('John Andrews')

    insert into @Names values ('John Adams')

    insert into @Names values ('John Matthews')

    insert into @Names values ('Mark Snow')

    select name,word from @Names

    inner join @Searchs on name like '%' + word + '%'

    this produces the following result

    name word

    John AndrewsJohn

    John Adams John

    John MatthewsJohn

    John AndrewsAndrews

    my goal is trying to return on 1 result - John Andrews.

    what do i need to do to achieve this ?

    PS: Is this "procedure" advisable to search multiple words ?

    Thank you in advance.

    That somewhat depends on what your Split function looks like. Is it using a while loop, xml or a tally table?

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/