Thanks for that … that is looking better. It is not selecting the first record anymore … just coming up with ‘unknown’ which in a way is better because it appears to be ignoring empty/blank entries.
Now I just have to work out why the %[NUMBER]% token isn’t matching anything
SELECT display_name FROM contacts WHERE (office_phone LIKE ‘%[NUMBER]%’ OR cell_phone LIKE ‘%[NUMBER]%’) and (office_phone is not null or cell_phone is not null)
i usually work with ms sql… but that should work for mysql too
Thanks for the info. Unfortunately that still doesn’t work.
Yeah the problem is that the first row in the database has an empty # for cell_phone so every call flags up the contact_name for the first row. You have got the problem right, but I tried your amended SQL command and I still get the same result.
SELECT display_name FROM contacts WHERE (office_phone LIKE ‘%[NUMBER]%’ OR cell_phone LIKE ‘%[NUMBER]%’) AND (office_phone IS NOT NULL OR cell_phone IS NOT NULL)
SELECT display_name FROM contacts WHERE (office_phone IS NOT NULL AND office_phone LIKE ‘%[NUMBER]%’) OR (cell_phone IS NOT NULL AND cell_phone LIKE ‘%[NUMBER]%’)
Then the chances are that the field isn’t actually null - it’s blank.
Try the following:-
SELECT display_name FROM contacts WHERE (office phone <> ‘’ AND
office_phone LIKE ‘%[NUMBER]%’) or (cell_phone <> ‘’ AND office_phone
LIKE ‘%[NUMBER]%’)
If you find you’re getting NULL fields returned as well, you might try:-
SELECT display_name FROM contacts WHERE (office phone IS NOT NULL AND
office phone <> ‘’ AND office_phone LIKE ‘%[NUMBER]%’) or (cell_phone IS
NOT NULL AND cell_phone <> ‘’ AND office_phone LIKE ‘%[NUMBER]%’)
This SQL format should be valid for just about any database type.
colinjack wrote:
[quote] Also tried this
SELECT display_name FROM contacts WHERE (office_phone LIKE ‘%[NUMBER]%’ OR cell_phone LIKE ‘%[NUMBER]%’) AND (office_phone IS NOT NULL OR cell_phone IS NOT NULL)