PDA

Click to See Complete Forum and Search --> : Searching all fields in SQL


casox
Mar 30th, 2000, 10:42 PM
Can anyone tell me how to search all fields in an SQL statement as opposed to just one? This is the code I want to change.

strQuery = "SELECT * FROM software WHERE Name LIKE '%" & SoftwareString & "%'"

I want to do a text search on all of the fields, not just the Name field. Thanks.

casox

bsmith
Mar 30th, 2000, 10:55 PM
You can try concatinating the Name and SoftwareString like this.
WHERE Name + SoftwareString Like "%"

I don't know if this is what you are looking for or not.

casox
Mar 30th, 2000, 11:04 PM
I'll explain better. There are 10 fields, Name is one of them. Instead of searching the table for a matching Name, I want to search the table for anything the user enters. ex. if one enters a name, it will query all fields and display the record that contains that name irregardless of what field it's in. I guess you might say that all of the data in the entire table needs to become one big text string and we then query for one specific field within that string. This would also hold true if one entered a serial number or network name etc. The query would simply search all the fields for a match. I've done this with string manipulation but now I'm doing it within a dbgrid and need to search with an sql statement. Yes / No ?

Thanks,

Kim

[Edited by casox on 03-31-2000 at 12:08 PM]

bsmith
Mar 30th, 2000, 11:45 PM
I would say you were on the right track with your first select statement. I created a stored procedure that executed the select statement I wanted. I passed in the arguments that I wanted to search for. I would add % to the end on the data the user entered so the LIKE would work correctly.

To answer your original quetsion, I don't know of a way to search all the fields without using the AND between each field.

Sorry

casox
Mar 31st, 2000, 12:06 AM
OK. It finally dawned on me what you were saying! Thanks, I'm sure the 'and' will work.

casox