Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

query database records using a parameter

records

  • Please log in to reply
2 replies to this topic

#1 mutago

mutago

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 478 posts

Posted 15 November 2011 - 12:47 PM

please guys Am using this code to query the database and is working but when i want to use parameter in the sql where clause,
it does not work again, i knew may be am using wrong parameter. any help please


 rs = con.query("SELECT * from product where price = '200')
this works but when used parameter %s in the where clause as showed below, it stop working

 rs = connection.query("SELECT * from product where price = '%s')

Okay in Python, i have achieved it this way



rs = "SELECT * FROM product where price='%s'" % (price)

thanks
  • 0

#2 fread

fread

    Programming God

  • Senior Member
  • PipPipPipPipPipPip
  • 897 posts
  • Location:Trinidad and Tobago
  • Learning:C, Java, C++, C#, PHP, Python, PL/SQL

Posted 15 November 2011 - 01:55 PM

rs = con.query("SELECT * from product where price = '200')
I don't think you need to put 200 in single quotes.
  • 0

#3 mutago

mutago

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 478 posts

Posted 15 November 2011 - 07:45 PM

well whether 200 is surround by single quote or not its working. What am saying is that i need to make the selection
using a parameter symbols that will replace the 200 so that the code will look like

rs = connection.query("SELECT * from product where price = [B]'%s'[/B]")


see in python below i did it this way and is working

rs = "SELECT * FROM product where price='%s'" % (price)

  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download