Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: WHERE clause and variables


Message #1 by jim@t... on Fri, 25 May 2001 18:04:52
I cannot for the life of me figure out how to use a variable in a WHERE 

clause. I need to retrieve only a particular record from a database, as 

defined by the unique key, a numeric value. If I use:

sql = "SELECT * FROM master WHERE key=5"

it works perfectly, extracting record number 5.

But if I assign idnum a value of 5 and use:

sql = "SELECT * FROM master WHERE key=idnum"

the web page crashes with "too few parameters" on that line in the ASP 

code.

Please HELP!

Message #2 by "Bo Johansen" <p2p.wrox.com@f...> on Sat, 26 May 2001 02:09:02 +0200
sql =3D "SELECT * FROM master WHERE key=3D'" & idnum & "'"



When ever you want to put a var. inside you sql do a '" thats ' and  " 

and & variable & " '



' " & variable & " '



Bo Johansen



----- Original Message -----

From: <jim@t...>

To: "ASP Databases" <asp_databases@p...>

Sent: Friday, May 25, 2001 6:04 PM

Subject: [asp_databases] WHERE clause and variables





> I cannot for the life of me figure out how to use a variable in a 

WHERE

> clause. I need to retrieve only a particular record from a database, 

as

> defined by the unique key, a numeric value. If I use:

> C> it works perfectly, extracting record number 5.

> But if I assign idnum a value of 5 and use:

> sql =3D "SELECT * FROM master WHERE key=3Didnum"

> the web page crashes with "too few parameters" on that line in the ASP 



> code.

> Please HELP!



Message #3 by "Dallas Martin" <dmartin@z...> on Fri, 25 May 2001 20:33:34 -0400
Change to:



 sql = "SELECT * FROM master WHERE key=" & idnum



Dallas





----- Original Message -----

From: <jim@t...>

To: "ASP Databases" <asp_databases@p...>

Sent: Friday, May 25, 2001 6:04 PM

Subject: [asp_databases] WHERE clause and variables





> I cannot for the life of me figure out how to use a variable in a WHERE

> clause. I need to retrieve only a particular record from a database, as

> defined by the unique key, a numeric value. If I use:

> sql = "SELECT * FROM master WHERE key=5"

> it works perfectly, extracting record number 5.

> But if I assign idnum a value of 5 and use:

> sql = "SELECT * FROM master WHERE key=idnum"

> the web page crashes with "too few parameters" on that line in the ASP

> code.

> Please HELP!

>


  Return to Index