Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using UNION to join tables

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I am trying to write a site search facility. As the information is in several tables I had the idea of using a UNION join. This works fine until I use a "WHERE LIKE '%keyword%'" clause.

Where am I going wrong? Any ideas? Many thanks
 
are you using access? if so why don't you just save your union query then when you open the recordset to search simply refence the union query and apply WHERE criteria to that.
Or in the union query statement you are currently(?) using to open the recordset, write WHERE statements for each SELECT statement?

I hope this solves your problem.

Please respond if this worked.
 
I have written the following queries
This works:
SQLString = "SELECT text FROM department WHERE text = '" & Request.Form.Item("keyword") & "' UNION SELECT text FROM unit WHERE text = '" & Request.Form.Item("keyword") & "'"

yet this doesnot:
SQLString = "SELECT text FROM department WHERE text LIKE '%" & Request.Form.Item("keyword") & "%' UNION SELECT text FROM unit WHERE text LIKE '%" & Request.Form.Item("keyword") & "%'"

Set rs = conn.Execute("" & SQLString & "")
I am using access but generating my own SQL queries? Is that wot you meant by saving the union query?
 
firstly, i think that you need to use 3 % for like statements ie "like '%%%& Request.Form.Item("keyword") & %%%'"

but what i meant by saving the union query was actually creating a union query in access (you need to do this in SQL view in the editor) with no criteria set on it, saving this query as say UNIONQUERY, then whe you open the recordset on the asp page, use code like this:

Code:
Set rs = conn.Execute("SELECT UNIONQUERY.* from UNIONQUERY WHERE text like'%%%& Request.Form.Item("keyword") & %%%'")

this works on my server using an access97 database...
 
Genius! It worked!

Not sure about the 3 %, but when I saved the query in Access it worked. I have not thought of writting queries actually in the access database before. Cool.

Genius, thanks very much for your time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top