Search for products with more than one word Delphi

Asked

Viewed 123 times

3

I am developing an application and would like to know how to research a product for more than one part of the name, for example:

Product:

DDR3 8Gb Notebook Ram Memory

I would like to do the search by typing for example: Mem DD or Mem Noteb or even Mem DD Note. Any idea how I could do that?

Tabela Produto
|Cod integer|
|Nome Varchar|
|Marca Varchar|
|Valor Numeric|

Note: I am using Delphi 10.2, Firebird 3.0

  • Enter the code you normally use to make queries by name as there are two ways to get the result you want. Or by event OnFilterRecord or by property Filtered.

  • Really ended up not putting , I’m sorry.

1 answer

5


You can only do this using good old SQL.
You would need to concatenate all the fields you want to filter and add an alias to it.

SELECT Nome+' '+Marca as campoBusca from tabela_produto

The return of this select would be:

         campoBusca
|Memória Ram DDR3 8Gb Notebook|

Then it would only be using a Where, but as we can not use alias in Where should be made a subquery, and in the return of this use the Where with the perador like so:

SELECT * FROM (SELECT Nome+' '+Marca as campoBusca from tabela_produto) AS tbl
    WHERE tbl.campoBusca like '%Mem%DD%'

Important
In the field where the user will type the words to the search you must replace the spaces by % and it must be present at the beginning and end of the researched term, as well as this in the example %Mem%DD%, it is he who makes the "magic" of searching anywhere in the field.

  • Murilo, that’s right, man. Thank you so much.

  • Glad it worked out! If the answer solved the problem, please check as correct to help other people who have the same problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.