ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 12th, 2002, 09:53 AM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 7
Send a message via MSN to aspnewbie
Spot the Syntax Error - Search Query

I'm getting this error, when I type "format bold" in the search box on a search form.

Microsoft OLE DB Provider for SQL Server (0x80040E14)
Line 1: Incorrect syntax near '%bold%'.

Here's the SQL statement.

Code:

strkeywords = Request.Querystring("strkeywords")
keywords = trim(replace((strkeywords),"'","''"))
keywordArray = split(keywords, " ", -1, 1)
kind = Request.Querystring("bolkind")

strSQL = "Select CourseName, Description from Courses" 
strSQL = strSQL & "WHERE Description LIKE "

	For item = 0 to UBound(keywordArray)
	 strSQL = strSQL & "'%" & keywordArray(item) & "%'"
	If item < UBound(keywordArray) Then
		strSQL = strSQL & " " & kind & " "
	End if
	Next


Any ideas? Thx

Reply With Quote
  #2  
Old November 12th, 2002, 10:59 AM
» Matt M « » Matt M « is offline
red house painter
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: South east England
Posts: 46 » Matt M « User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to » Matt M « Send a message via AIM to » Matt M «
I think the problem is that you have the '% %' characters within the loop, so each search term will have those wrapped around it.

You need to find someway of doing this outside of the loop.

Thats what I think is happening.

Reply With Quote
  #3  
Old November 12th, 2002, 11:18 AM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 7
Send a message via MSN to aspnewbie
Talking

Found it! Moved the field name into the loop!

Code:

strSQL = "Select CourseName, CourseID, Application, Description from Courses " 
strSQL = strSQL & "WHERE "

	For item = 0 to UBound(keywordArray)
	 strSQL = strSQL & " (Description Like '%" & keywordArray(item) & "%')"
	If item < UBound(keywordArray) Then
	 strSQL = strSQL & kind 
	End if
	Next

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Spot the Syntax Error - Search Query


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 4 hosted by Hostway