querying more than one field in a table

Results 1 to 2 of 2

Thread: querying more than one field in a table

  1. #1
    Join Date
    Dec 1969

    Default querying more than one field in a table

    I&#039;m trying to do a basic search button that will query two fields in a table, but I can&#039;t seem to find the correct way of doing it anywhere. <BR><BR>To do the search I&#039;ve set up a variable taken from the submit button then I&#039;m using that to query the DB...<BR><BR>If bsearch=rs.fields("itemdesc") then<BR><BR>however, I&#039;m not sure how to change this line of code into searching two fields inside the table?<BR><BR>Can anyone shed any light onto this for me?

  2. #2
    Join Date
    Dec 1969

    Default Basic SQL

    Build your SQL query like this:<BR><BR>SQL = "Select * from tablename where itemdesc like &#039;%" & bsearch & "%&#039; or otherfield like &#039;%" & bsearch & "%&#039;"<BR><BR>What this is saying is get all the fields from tablename where the bsearch value is somewhere in itemdesc or somewhere in otherfield. This way all you&#039;ll get in your recordset will be the values you need avoids looping the recordset to compare and is more efficient. Want a great SQL tutorial? Check this out:<BR><BR>First read up on select:<BR>http://www.w3schools.com/sql/sql_select.asp<BR><BR>then check out like and where:<BR>http://www.w3schools.com/sql/sql_where.asp<BR><BR><BR><BR>

Posting Permissions

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