Python Forum
Add Variable to select query
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add Variable to select query
#1
Hi,

I cant quite work out how to add a variable into a SELECT query.

My attempt is

    query = ("SELECT distinctrow UPC, ItemFriendlyNames, ItemName, Brand, Model, Retailer, ItemID FROM my.view where ItemFriendlyNames like "%(pSearch)%" order by UPC, Model, Retailer")
    data = (event['pSearch'],)
        
    cursor.execute(query,data)
    rows = cursor.fetchall()
I have a field called pSearch that contains the user input. In addition I want to use like and add %% to each end of the user input.

Thanks in advance for any assistance

Todd
Reply
#2
This will help: https://www.ibm.com/support/knowledgecen...54696.html
Reply
#3
Thanks Larz60+,

Looks like it would be easier to use a sp instead.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error using mariadb select query with form in python? shams 2 1,994 Jul-29-2021, 12:30 PM
Last Post: shams
  I need a query to select the numbers that include 2 digits of 3 omidvakili 1 1,636 Sep-20-2019, 03:49 PM
Last Post: Yoriz
  SQL query with a variable amount of parameters Antares 10 6,842 Jul-08-2019, 02:24 PM
Last Post: Antares
  SELECT statement query question using a variable DT2000 2 3,010 Feb-23-2019, 07:35 AM
Last Post: DT2000
  SQL select join operation in python(Select.. join) pradeepkumarbe 1 2,231 Feb-14-2019, 08:34 PM
Last Post: woooee
  python variable in SQL query takaa 5 31,410 Nov-23-2017, 10:12 AM
Last Post: takaa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020