Click to See Complete Forum and Search --> : How to get rid of this comma!!?!


gilgalbiblewhee
08-02-2005, 03:20 PM
THe code is this:

If Trim(Request.QueryString("id")) <> "" Then
myarray = split(id," ")
whereclause=" id = " & myarray(0)
for counter=1 to ubound(myarray)
whereclause = whereclause & " OR id = " & myarray(counter)
next
SQL = SQL & whereclause
iCounter = iCounter + 1
End If


It gives this error:
[QUOTE]
SELECT * FROM bible WHERE id = 1, OR id = 2

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error (comma) in query expression 'id = 1, OR id = 2'.
[\QUOTE]

How do you get rid of this comma?

buntine
08-02-2005, 07:58 PM
Alter the second parameter of the split function. I am assuming the ID list is a comma delimited.

myarray = Split(id, ",")

You will need to enapsulate each reference of 'id' in square brackets within your SQL query, too. It is a reserved word. I would highly recommend you change it to something like bibleID.

Regards.

gilgalbiblewhee
08-02-2005, 08:38 PM
Problem fixed, when I replaced

' whereclause = whereclause & " OR id = " & myarray(counter)

with

whereclause = left(whereclause,len(whereclause)-1) & " OR id = " & myarray(counter)

I don't know why, even though the query states:
SELECT * FROM bible WHERE id = 1 OR id = 2
The result writes one id alone.
-----
To give more details, I believe that the reason that it didn't pick up the 2nd id was because it didn't recognize the 2nd selected checkbox. Here is the question/response's question page. It picked up the first checkbox but not the 2nd.

<%
Do until RS.eof
Dim strText, strFind
%>
<input type="checkbox" value="<%=RS("id")%>" name="id"><br/>
<%
Response.Write("<textarea ")
response.write("name=" & chr(34) & "Keywordh" & RS("id") & chr(34))
response.write(" rows=" & chr(34) & "3" & chr(34))
response.write(" cols=" & chr(34) & "64" & chr(34) & ">")
response.write("</textarea>")
rs.movenext


-------
This is what I did:

For each x in myarray

SQL= "SELECT * "
SQL = SQL & " FROM bible WHERE "

If Trim(Request.QueryString("id")) <> "" Then
myarray = split(id," ")
whereclause=" id = " & x
for counter=1 to ubound(myarray)
' whereclause = whereclause & " OR id = " & myarray(counter)
' whereclause = left(whereclause,len(whereclause)-1) & " OR id = " & myarray(counter)
next
SQL = SQL & whereclause
iCounter = iCounter + 1
End If
next

This is what I got:
Microsoft VBScript runtime error '800a01c3'

Object not a collection and points to
For each x in myarray