1 (edited by VascoMorais 2018-05-09 12:09:08)

Topic: SQL Execute from Multiple Where's

hello, i'm trying to figure out a way to search from mutiple "where's"

here's my syntax, doesn't seem to work:

('SELECT id FROM cliente WHERE contacto1 LIKE "%'+contacto1+'%" and WHERE nome LIKE "%'+nome+'%"')

Contacto1 and nome are vars of course

Many thanks in advance smile

Re: SQL Execute from Multiple Where's

I would try:

To select something with contacto1 AND nome:
'SELECT id FROM cliente WHERE contacto1 LIKE "%'+contacto1+'%" and nome LIKE "%'+nome+'%"';

To select something with contacto1 OR nome:
'SELECT id FROM cliente WHERE contacto1 LIKE "%'+contacto1+'%" or nome LIKE "%'+nome+'%"';




Basically you 'select' 'something' 'from' 'somewhere' 'where' 'constraint is' 'something' 'or/and' 'something else'. No need to repeat WHERE in same select.

Re: SQL Execute from Multiple Where's

okay here's what i have atm:

frm_assistencia.ComboBox_cl_idcliente.dbItemID := SqlExecute('SELECT IFNULL(id, -1)id FROM cliente WHERE ((nome like "%'+nome+'%") and (contacto2 like "%'+contacto2+'%") and (contacto1 like "%'+contacto1+'%"))');

in this situation, i have several edit boxes that i can type whatever i want in them, and the sql will indeed search for each and every possibility trying to figure out it's nº1 best guess.
But if i have a (null) entry on sql , for instance, if only one contact is avaiable, with this syntax i am not able to get the search to work.

the only other way to do this is to create multiple sql execute commands, one for each edit box. something i'm trying to avoid to keep this database simple and effective