Home > SQL Development > SQL string trouble

SQL string trouble



<i><b>Originally posted by : fred (fred_espi@hotmail.com)</b></i><br /><br />Hi, I a student trying to learn ASP but I have some troubles with my SQL querry.<br /><br />I want to have a querry that will depends on the value of a param.<br /><br /><br /><%<br /><br />Response.Buffer = true<br />dim cnn,rst<br />set cnn = Server.CreateObject("ADODB.Connection")<br />set rst = Server.CreateObject("ADODB.RecordSet")<br />cnn.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("db/myDataBase.mdb") & ";"<br /><br />dim prix<br />prix = CStr(Request.QueryString("pr"))<br /><br />sqltext = "SELECT * FROM table WHERE prix=' ??? ' "<br />rst.Open sqltext,cnn,3,3<br />%><br /><br />I don't know how to insert my dim (prix) as a string into the SQL command. I always got an error message.<br /><br />Is anybody able to help me please, it would be very nice.<br />Thank you very much,<br />Sincerely,<br />Fred

    
Guest


<i><b>Originally posted by : Jerry Scannell (JScannell1@home.com)</b></i><br /><br /><br /><br />------------<br />fred at 5/16/2001 7:30:16 AM<br /><br /><br />Hi, I a student trying to learn ASP but I have some troubles with my SQL querry.<br /><br />I want to have a querry that will depends on the value of a param.<br /><br /><br /><%<br /><br />Response.Buffer = true<br />dim cnn,rst<br />set cnn = Server.CreateObject("ADODB.Connection")<br />set rst = Server.CreateObject("ADODB.RecordSet")<br />cnn.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("db/myDataBase.mdb") & ";"<br /><br />dim prix<br />prix = CStr(Request.QueryString("pr"))<br /><br />sqltext = "SELECT * FROM table WHERE prix=' ??? ' "<br />rst.Open sqltext,cnn,3,3<br />%><br /><br />I don't know how to insert my dim (prix) as a string into the SQL command. I always got an error message.<br /><br />Is anybody able to help me please, it would be very nice.<br />Thank you very much,<br />Sincerely,<br />Fred<br /><br />Fred,<br /><br />The answer is quite simple, actually. you need to create a string that contains the select statement plus the passed varialbe. That is accomplished like so:<br /><br />sqltext = "SELECT * FROM table WHERE prix = '" & prix & "'"<br /><br />Note that you have to mix the single (') and double (") quotes so you will end up with something like the following:<br /><br />SELECT * FROM table WHERE prix = 'prixvalue'<br /><br />

Was this answer helpful ? Yes No   
Guest


sqltext = "SELECT * FROM table WHERE prix = '" & prix & "'"

for text params

sqltext = "SELECT * FROM table WHERE prix = " & prix

for numerics

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved