Syntax error (missing operator) in query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aaron6098
    New Member
    • Dec 2009
    • 1

    #1

    Syntax error (missing operator) in query

    I am trying to finish my final project for my programing class. i keep on getting Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
    [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'OrderID ='.
    /students/11/scripts/OrdersLines.asp , line 12

    I place the ' ;' and then i recieve
    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E07)
    [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
    /students/11/scripts/OrdersLines.asp , line 12


    can anyone help me
    Code:
    <%
    OrderID = request.QueryString("OrderID")
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.open "Prj11"
    SQLCmd = "Select CustomerID, LogTime, Description, ShippingAddress, SCity, SZipCode, SState, BillingAddress, BCity, BZipCode, BState, OrderID FROM Orders WHERE OrderID = " & OrderID & ""  (Line 12)
    
    Set rsOrder = Conn.Execute(SQLCmd)
    
    CustomerID = replace(rsOrder("CustomerID"),"'","''")
    LogTime = replace(rsOrder("LogTime"),"'","''")
    Description = replace(rsOrder("Description"),"'","''")
    ShippingAddress = replace(rsOrder("ShippingAddress"),"'","''")
    SCity = replace(rsOrder("SCity"),"'","''")
    SZipCode = replace(rsOrder("SZipCode"),"'","''")
    SState = replace(rsOrder("SState"),"'","''")
    BillingAddress = replace(rsOrder("BillingAddress"),"'","''")
    BCity = replace(rsOrder("BCity"),"'","''")
    BZipCode = replace(rsOrder("BZipCode"),"'","''")
    BState = replace(rsOrder("BState"),"'","''")
    
    SQLCmd = "SELECT CustomerName FROM Customer WHERE CustomerID = '" & CustomerID & "'"
    
    Set rsClient = Conn.Execute(SQLCmd)
    CustomerName = Replace(rsClient("CustomerName"),"'","''")
    %>
    Last edited by jhardman; Dec 21 '09, 06:37 AM. Reason: added code tags
  • VipinKB
    New Member
    • Dec 2009
    • 3

    #2
    aaron6098,

    Your problem is probably because of order Id value being blank in the querystring...

    Try printing out OrderID variable before you use it in SQL..

    Also, alternatively to nail the issue, you can hard-code the OrderId in SQL and see if it works...

    But, my guess is you are probably missing orderId value in SQL...also try printing SQL before firing it to database engine..

    Hope this helps you to get to issue.

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      Vipin is quite likely right, but in the end, this is a common problem with a simple solution: print out your query (response.write SQLCMD) and LOOK AT IT! When you look at the final query there is a 90% chance you will see the problem. My first guess: too many quote marks. Numerical fields should not be within single quote marks in a SQL query. "...WHERE customerID = '1234'" is almost definitely wrong (this is in the second query, but it illustrates the point). The line 12 ends with 2 quote marks for some reason. I can't tell why. It is fine to say
      Code:
      SQLCmd = "Select CustomerID, LogTime, Description, ShippingAddress, SCity, SZipCode, SState, BillingAddress, BCity, BZipCode, BState, OrderID FROM Orders WHERE OrderID = " & OrderID
      of course, if vipin is correct and orderID is blank, then if you printed out the query, you would see
      Code:
      Select CustomerID, LogTime, Description, ShippingAddress, SCity, SZipCode, SState, BillingAddress, BCity, BZipCode, BState, OrderID FROM Orders WHERE OrderID =
      So to recap, the solution is to print out your query and look at it!

      Jared

      Comment

      Working...