Forum Moderators: open

Message Too Old, No Replies

Newbie SQL and variables question

         

Neural

4:31 pm on Nov 15, 2004 (gmt 0)

10+ Year Member



Hi all, I turn to you for help again. I am trying to do something really simple and I can't for the life of me find out what the syntax should be for using variables in an SQL statement... Here's the source:-

dim make_name
dim model_name
make_name=request.form("make_search")
model_name=request.form("model_search")
%>

<%
Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("admin\db\webpublish.mdb")
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
SQL_query = "SELECT * FROM tblWebVehicles WHERE Make=((make_name))"
Set RS = MyConn.Execute(SQL_query)
%>

<% while not rs.eof%>
<FONT face="Arial, Helvetica, sans-serif" size=2><B><FONT color="#000000" size=4>
<%=rs("make")%><BR>
<%rs.movenext
wend
%>

..Nice and simple, I am passing an input from a form via the variable 'make_search' and re-assigning it to be called 'make_name.

Now, my problem is with the SQL string.. I don't know how to incorporate the variable 'make_name' into the string. Here's the line that I'm stuck on again:-

SQL_query = "SELECT * FROM tblWebVehicles WHERE Make=(make_name)"

I want to say "Select all the cars from the database that match the "make" field that the user inputted on the previous form".. a sort of search engine for the database.

Could anyone tell me what the correct syntax is for the query please? I have scoured the net trying to find out how to use variables in the SQL string and I have tried umpteen combinations to no avail.

Any help is greatly received. Thank you.

dotme

4:50 pm on Nov 15, 2004 (gmt 0)

10+ Year Member



SQL_query = "SELECT * FROM tblWebVehicles WHERE Make=('" & make_name & "')"

Easy_Coder

4:51 pm on Nov 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So what are the columns on tblWebVehicles?

Neural

4:52 pm on Nov 15, 2004 (gmt 0)

10+ Year Member



Wow... almost instant help... Thank you very much indeed. I will try that out now.

The columns in the db are MAKE MODEL VARIANT PRICE

Cheers

Neural

4:54 pm on Nov 15, 2004 (gmt 0)

10+ Year Member



Works a treat ... thank you.