Click to See Complete Forum and Search --> : Like command


Karsten Döring
September 29th, 1999, 10:14 AM
Hi,

I use following SQL-String to get all eMails in my Access Database belonging to the same domain:

sql.Format( "SELECT login, passwort, email FROM Accountdaten WHERE email Like '*%s*'", domain );

But for some reason LIKE doesn't work. Can u tell me where the problem is? I have MDAC SP1 installed.

Thanx in advanced

Karsten

James Curran
September 29th, 1999, 12:02 PM
In SQL, the wildcard character is not "*", it's "%". SO, to say "every domain with 'microsoft' in it, you'd write it as:
SELECT login, passwort, email FROM Accountdaten WHERE email Like '%micorosoft%'"

Of course, using th Format() complictes this:

sql.Format( "SELECT login, passwort, email FROM Accountdaten WHERE email Like '%%%s%%'", domain );




Two %s become one % when passed through printf/format


Truth,
James
http://www.NJTheater.com
http://www.NJTheater.com/JamesCurran

Karsten Döring
October 1st, 1999, 06:35 AM
Hi,

jeah, that really works. Thanx a lot.

But I still have another question. Ist there a command for searching all fields at one time for a keyword?

at the moment I have to do it with Like for each field. Ist there another command available which can do this on it's own? If yes, can u give me an example?

Thanx in advance

Karsten