ASP - SQL statement

Results 1 to 4 of 4

Thread: ASP - SQL statement

  1. #1
    Join Date
    Dec 1969
    Posts
    169

    Default ASP - SQL statement

    Hello,<BR><BR>I wonder what is wrong with the following sql2 select statement?<BR>It gives an error message of<BR><BR>Microsoft OLE DB Provider for ODBC Drivers error &#039 80040e14&#039 <BR><BR>[Microsoft][ODBC Microsoft Access 97 Driver] Invalid SQL statement; expected &#039DELETE&#039, &#039INSERT&#039, &#039PROCEDURE&#039, &#039SELECT&#039, or &#039UPDATE&#039. <BR><BR>viewcal.asp, line 29 <BR><BR>------------------------------------------------<BR><BR>while not rs.eof<BR> MyID = rs("ID")<BR> If request.form("MyID") = "ON" Then<BR> If processed = 0 Then<BR> sql2 = "select * from Events where ID = "&request.form(rs("ID"))&" "<BR> processed = 1<BR> else<BR> sql2 = sql2 & "or ID = "&request.form(rs("ID"))&" "<BR> End If<BR> End If<BR><BR>rs.Movenext<BR>Wend

  2. #2
    Join Date
    Dec 1969
    Posts
    511

    Default RE: ASP - SQL statement

    I&#039m not sure what you are doing with the request.form(rs("ID")) part, you had already set this value to a varible (MyID), why not use that instead. This will put less strain on the server.<BR><BR>Try getting the ASP to display your SQL statment before you execute it, that nearly always works for me, show up any mistakes you may have made with your sintax.<BR><BR>Response.Write sql2<BR><BR>The only other thing I can think of is that ID might not be a number? inwhich case you would need single quotes around it, but it would have given you a different error message if that was the case.<BR><BR>Hope that helps<BR><BR>Pete

  3. #3
    Ian S Guest

    Default RE: ASP - SQL statement

    You should use Uppercase in a SQL statement<BR><BR>sql2 = "SELECT * FROM Events WHERE ID = " & request.form(rs("ID"))&" <BR><BR>I would try something like so:<BR><BR>if the ID is a number:<BR><BR>sql2 = "SELECT * FROM Events WHERE ID=" & request.form("ID")<BR><BR>if the ID is a string:<BR><BR>sql2 = "SELECT * FROM Events WHERE ID=&#039" & request.form("ID") & "&#039"<BR><BR>hope this clears it up :)<BR>

  4. #4
    Join Date
    Dec 1969
    Posts
    1,016

    Default RE: ASP - SQL statement

    The result of your select statement is missing necessary qoutes. Try formating your string like<BR><BR>"SELECT * From Events WHERE ID = " & char(34) & request.form(rs("ID")) & char(34)<BR>The qoute at the beginning is closed by the qoute at the equal sign. The result would be <BR>SELECT * FROM Events WHERE ID = rs("ID") missing the qoutes.<BR>The char(34) concatinated at the begining of the recordset varialble and at the end will complete the statement.<BR><BR>Have Fun


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •