Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Search query through 3 different fields

Author  Topic 

monaya
Yak Posting Veteran

58 Posts

Posted - 2014-12-12 : 15:19:06
I have 2 tables.

Clients
Contacts (multiple contacts for one client)

I'm trying to do a search that pulls a contacts where the search matches either the First Name, last Name or the clients name. If it does return clients, I'd like it to also return all the contacts associated with it.

I have two problems:

1. The query is not bringing up a lot of clients. In many cases a letter brings nothing back. Like G and H even though A and B return results.

2. If it finds a client it only returns one contact. I'd like it to return all contacts for the client.

Here's my query:

SELECT addressbook.clientid, clients.clientname, addressbook.addressid, addressbook.fname, addressbook.lname FROM clients, addressbook where clients.clientid = addressbook.addressid 
AND (addressbook.fname LIKE
'".strtoupper($_GET['txtsearch'])."%' OR addressbook.lname LIKE
'".strtoupper($_GET['txtsearch'])."%' OR clients.clientname LIKE
'" . strtoupper($_GET['txtsearch'])."%')

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-12-12 : 16:15:46
I presume that the expression ".strtoupper($_GET['txtsearch'])." is resolved by PHP before sending the query to SQL Server. Can you post some examples of the actual query?
Go to Top of Page
   

- Advertisement -