• duro654321 (11/17/2012)


    hello,

    right now on my search page the sql query i am using is similar to:

    select * from table where name like '%search%'

    and it returns the exact phrases perfectly

    however if search = "car red" there are no results

    i want it to be able to return "red card" results also

    basically i want it to be:

    select * from table where name like '%car%' or name like '%red%'

    any ideas? thanks!

    Just do what you want to be, that is right T-SQL:

    select * from table where name like '%car%' or name like '%red%'

    or, if want anything containing "car" and "red" in the order mentioned, you should do this:

    select * from table where name like '%car%red%'

    or, if want anything containing "car" and "red" in any order, you can do this:

    select * from table where CHARINDEX('car',name) > 0 and CHARINDEX('red',name) > 0

    But, the problem with all above samples is - performance! You may find it not satisfactory.

    Then consider using Full-Text search.

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]