SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 16th, 2001, 09:30 AM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,575 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 22
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

Reply With Quote
  #2  
Old June 25th, 2001, 03:59 PM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,575 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 22
<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 />

Reply With Quote
  #3  
Old October 14th, 2003, 10:53 AM
m_lazor m_lazor is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Luxembourg
Posts: 156 m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
sqltext = "SELECT * FROM table WHERE prix = '" & prix & "'"
for text params
sqltext = "SELECT * FROM table WHERE prix = " & prix
for numerics

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > SQL string trouble


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway