Results 1 to 5 of 5

Thread: Searching all fields in SQL

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Oak Creek, WI, USA
    Posts
    92
    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

  2. #2
    Lively Member
    Join Date
    Jan 2000
    Location
    Springfield, IL
    Posts
    124
    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.


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Oak Creek, WI, USA
    Posts
    92
    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]

  4. #4
    Lively Member
    Join Date
    Jan 2000
    Location
    Springfield, IL
    Posts
    124
    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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Oak Creek, WI, USA
    Posts
    92
    OK. It finally dawned on me what you were saying! Thanks, I'm sure the 'and' will work.

    casox

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width