Python Forum

Full Version: Add Variable to select query
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Thanks Larz60+,

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