ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 29th, 2003, 06:22 AM
m175400 m175400 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 19 m175400 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Searching memo fields for words containing a hyphen returns only one result

I have built a search feature for a site which searches 4 fields, 2 in one table and 2 in another. It's an Access database. It works a treat when searching for anything except something like "I'd", or "it's" etc. Anything with a hyphen in returns one result, or less than there in fact are.

My SQL statement is as follows:

strSQL = "select id as strID, tableID as strTableID, tagline as strTagline, content AS strContact FROM news where tagline LIKE '%" & searchString & "%' OR content LIKE '% " & searchString & "%' UNION ALL select id as strID, tableID as strTableID, tagline AS strTagline, content AS strContent from databank where tagline LIKE '%" & searchString & "%' OR content LIKE '%" & searchString & "%' ORDER BY strID"

Hope you can help!

Last edited by m175400 : September 29th, 2003 at 06:26 AM.

Reply With Quote
  #2  
Old September 29th, 2003, 11:39 AM
don_sparko's Avatar
don_sparko don_sparko is offline
Digitally Challenged
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 280 don_sparko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 6
did you try using this where you have searchString
Code:
replace(searchString,"'","''")

since most ms db stuff doesn't like the ' character. let me know if this works
__________________
My brain cells are like a storm trooper's armor: useless

Reply With Quote
  #3  
Old October 8th, 2003, 10:01 AM
m175400 m175400 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 19 m175400 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by don_sparko
did you try using this where you have searchString
Code:
replace(searchString,"'","''")

since most ms db stuff doesn't like the ' character. let me know if this works


Yep, changed all instances of ' in the database to '', then searched for '' instead. Again, returns the same incorrect number of results, identical to that before

Reply With Quote
  #4  
Old October 8th, 2003, 04:26 PM
don_sparko's Avatar
don_sparko don_sparko is offline
Digitally Challenged
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 280 don_sparko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 6
just an idea. you shouldn't have to change your text in the database to '' (two single quotes) you should just use the
Code:
replace(string,"'","''")
when you are inserting it, and use that as well when you are searhing for it. also do any of the fields you are searching contain NULL values?

Reply With Quote
  #5  
Old October 9th, 2003, 03:50 AM
m175400 m175400 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 19 m175400 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by don_sparko
just an idea. you shouldn't have to change your text in the database to '' (two single quotes) you should just use the
Code:
replace(string,"'","''")
when you are inserting it, and use that as well when you are searhing for it. also do any of the fields you are searching contain NULL values?


Sorry, I realise I should use

Code:
replace(string,"'","''")


when inserting the records in the first place. I just meant that for the purpose of testing this I manually changed all entries to reflect this rather than re-adding new database items via the web site front end.

None of the records have NULL values either. Thanks for your continued help with this matter.

I have switched to trying a paramaterized statement now, in an effort to get it to work and improve performance, using a query in access itself called 'qrySearch' which I call from my ASP. However, the query doesn't seem to return any results at all, regardless of what I search for. It is as follows:

PARAMETERS searchText Text ( 255 );
SELECT id as strID, tableID AS strTableID, tagline AS strTagline, content AS strContact FROM news WHERE

(((tagline)LIKE[searchText]))


OR

(((content)LIKE[searchText]))


UNION ALL select id AS strID, tableID AS strTableID, tagline AS strTagline, content AS strContent FROM databank WHERE

(((tagline)LIKE[searchText]))


OR

(((content)LIKE[searchText]))
ORDER BY strID;

Reply With Quote
  #6  
Old October 9th, 2003, 12:12 PM
don_sparko's Avatar
don_sparko don_sparko is offline
Digitally Challenged
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 280 don_sparko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 6
Code:
(select item1, item2 from table1 where item1 like '%" & replace(request.form("searchstring"),"'","''") & "%' or item2 like '%" & replace(request.form("searchstring"),"'","''") & "%')
union all
(select item1, item2 from table2 where item1 like '%" & replace(request.form("searchstring"),"'","''") & "%' or item2 like '%" & replace(request.form("searchstring"),"'","''") & "%')

Reply With Quote
  #7  
Old October 10th, 2003, 06:28 AM
m175400 m175400 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 19 m175400 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I've tried changing my query in access to the following as you suggested, but still no joy. It returns nothing regardless of what I enter as the search parameter. Even a simple search for "a" returns no matches, and this is wholy in access itself, not even using ASP. I'm starting to loose my mind here. Am I being really thick?

PARAMETERS searchText Text ( 255 );
select id, tagline, content FROM news WHERE

(((tagline)LIKE[searchText]))


OR

(((content)LIKE[searchText]))

UNION ALL select id, tagline, content FROM databank WHERE

(((tagline)LIKE[searchText]))


OR

(((content)LIKE[searchText]))
ORDER BY id;

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Searching memo fields for words containing a hyphen returns only one result


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT