Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: Using Querystring in SQL Statement


Message #1 by bayou_ranch@m... on Thu, 2 May 2002 13:47:31
I have attempted to create a SQL statement to retrieve records for 
display.  If I use an actual string the statement functions properly, 
however, if I us a variable such as a variable obtained through 
the "MyVariable = Request.Querystring("item"), I get error messages.  Here 
is the statment using an actual string.
 
rs.Open "SELECT * FROM prices WHERE Listing= 'radio' ORDER BY name ASC" , 
DB_CONNSTRING
 
That statment works, however this one does not:
 
rs.Open "SELECT * FROM prices WHERE Listing= MyVariable ORDER BY name 
ASC" , DB_CONNSTRING
 
I have used many variations such as 
 
rs.Open "SELECT * FROM prices WHERE Listing=" & MyVariable & " ORDER BY 
name ASC" , DB_CONNSTRING
 
Depending on the variation I get one of several error messages.
 
Can someone please tell me what I am missing?  Thanks
Message #2 by Martin Lee <access@o...> on Thu, 02 May 2002 21:14:01 +0800
Try adding single quotes before and after MyVariable.

rs.Open "SELECT * FROM prices WHERE Listing= '" & MyVariable & "' ORDER BY
name ASC" , DB_CONNSTRING

Martin

At 01:47 PM 5/2/2002 +0000, you wrote:
>I have attempted to create a SQL statement to retrieve records for
>display.  If I use an actual string the statement functions properly,
>however, if I us a variable such as a variable obtained through
>the "MyVariable = Request.Querystring("item"), I get error messages.  Here
>is the statment using an actual string.
>
>rs.Open "SELECT * FROM prices WHERE Listing= 'radio' ORDER BY name ASC" ,
>DB_CONNSTRING
>
>That statment works, however this one does not:
>
>rs.Open "SELECT * FROM prices WHERE Listing= MyVariable ORDER BY name
>ASC" , DB_CONNSTRING
>
>I have used many variations such as
>
>rs.Open "SELECT * FROM prices WHERE Listing=" & MyVariable & " ORDER BY
>name ASC" , DB_CONNSTRING
>
>Depending on the variation I get one of several error messages.
>
>Can someone please tell me what I am missing?  Thanks

Message #3 by bayou_ranch@m... on Thu, 2 May 2002 14:55:51
> 
Yes, Your suggestion worked perfectly.  I was really pulling my hair out 
trying different combinations to get the syntax correct.  I can't tell you 
how greatful I am for the help!


Try adding single quotes before and after MyVariable.

rs.Open "SELECT * FROM prices WHERE Listing= '" & MyVariable & "' ORDER BY
name ASC" , DB_CONNSTRING

Martin

At 01:47 PM 5/2/2002 +0000, you wrote:
>I have attempted to create a SQL statement to retrieve records for
>display.  If I use an actual string the statement functions properly,
>however, if I us a variable such as a variable obtained through
>the "MyVariable = Request.Querystring("item"), I get error messages.  Here
>is the statment using an actual string.
>
>rs.Open "SELECT * FROM prices WHERE Listing= 'radio' ORDER BY name ASC" ,
>DB_CONNSTRING
>
>That statment works, however this one does not:
>
>rs.Open "SELECT * FROM prices WHERE Listing= MyVariable ORDER BY name
>ASC" , DB_CONNSTRING
>
>I have used many variations such as
>
>rs.Open "SELECT * FROM prices WHERE Listing=" & MyVariable & " ORDER BY
>name ASC" , DB_CONNSTRING
>
>Depending on the variation I get one of several error messages.
>
>Can someone please tell me what I am missing?  Thanks


  Return to Index