1

I'm attempting to use a variable for the column field in the SQL statement however it shoots back the following error at me:

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

[Microsoft][ODBC Text Driver] Syntax error (missing operator) in query expression '= 'Yes''.

/junk/dbresults.htm, line 31

THE CODE:

<%
    Dim connectString, connect, conDB, con
    connectString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DBQ=" & Server.MapPath("data")
          src_abn = Request.QueryString("abn")
          src_cat = Request.QueryString("cat")
    set connect = Server.CreateObject("ADODB.connection")
    connect.open connectString

    if src_abn = "all" then
    conDB = "SELECT * FROM cont.csv WHERE " & src_cat & " = 'Yes'"  
    else
    conDB = "SELECT * FROM cont.csv WHERE ucase(abn) LIKE ucase('%"+src_abn+"%')"   
    end if

    set con = connect.execute(conDB)
%>
1
  • 1
    Does src_cat happen to be an empty string? Commented Jan 9, 2013 at 21:18

2 Answers 2

1

Looks like the value of src_cat contains spaces or other characters that create an invalid query. Try changing that line to this (with brackets):

conDB = "SELECT * FROM cont.csv WHERE [" & src_cat & "] = 'Yes'"
Sign up to request clarification or add additional context in comments.

1 Comment

Worth to warn the OP here of SQL Injection attack.
0

Fixed it, the variables were not delcared.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.