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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems Using SQL "LIKE"

Status
Not open for further replies.

tempoman

Programmer
May 9, 2000
41
AU
I am trying to compare a string value from form input with the a string in the database. However the sql Like does not seem to work. I have tried and tried but can't seem to create a match.

Following is some of my code.

Journal = Request.Form("journal")
findpub = "Select * " &_
"From Publication " &_
"Where 'Publication.Journal' Like '&JournalIn&%'"

Am I doing it correctly or is there a better way for this to work?

Thanx for any suggestions.



[sig][/sig]
 
Try
Code:
objRS.Filter = "journal like " & "'%" & "journal" & "%'"
HTH,

Kevin [sig][/sig]
 
Thanks for your help kevink, your solution works however does not solve my problem. I worked why it doesnt work, it seems that it only works for singular works.

However I require it to match more than one word at a time.
e.g. "Journal Number 58" needs to be checked. If I put in just "Journal" the records come back succesfully but I need the whole string.

Is there a way that I can compare the whole string?
Have you got any suggestions? or does anyone else have any suggestion?

The following is my code:

Journal = Request.Form("journal")
findpub = "Select * " &_
"From Publication "

Set matchpub = cn.Execute(findpub, , adCmdText)

matchpub.Filter = "journal like " & "'%" & "journal" & "%'"

While Not matchpub.EOF
Response.Write matchpub(&quot;Author&quot;) &&quot; <br>&quot;
matchpub.MoveNext
Wend


Thanx for any suggestions. [sig][/sig]
 
Hmm .. it won't work unless the search phrase is exactly the same as the record entry ....

Have you tried other ideas - like creating drop down lists which are exactly the record entry etc., or does it have to be a search form?

If it has to be a seach form, then the only way I can think off is to split() the search phrase up and then do a query using WHERE AND clauses

Kevin [sig][/sig]
 
Get rid of double quotes in your filter expression and put it as follows:
matchpub.Filter = &quot;journal like &quot; & &quot;'%&quot; & journal & &quot;%'&quot;
It's because when you use it like [red]&quot;journal&quot;[/red] your filter's looking for the title(if that's the field you're quering), containing word &quot;journal&quot;.
But you need to use a variable journal= request.form(&quot;journal&quot;) instead. Meaning the value of this variable.
 
Thanx alot guestg your suggestion works. I now have a fully functional search engine.

Thanx again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top