|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > Spot the Syntax Error - Search Query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|