So, I am now linking Python to SQL to pull out client information. Unfortunately, I am getting some errors regarding SQL. I try to use the LIKE operator and the wildcard%, but I keep getting errors because Python doesn't like%. As a result, it pretends that the variable between% s does not exist. Here is what I mean:
SELECT custnbr,
firstname,
middleint,
lastname
FROM lqppcusmst
WHERE custnbr = ? AND firstname LIKE ?
Right now, I'm just checking this, so I'm just using the client number and name. I give him the meaning:
remote_system_account_number = request.DATA['remote_system_account_number']
remote_system_first_name = request.DATA['remote_system_first_name']
Since what I am writing is searching for clients in the database, there is a chance that there may be empty entries, so I have this:
if remote_system_account_number != '':
SQL_where += ' custnbr = ? '
parameters += "remote_system_account_number"
if remote_system_first_name != '':
SQL_where += ' AND firstname LIKE ? '
parameters += ", %remote_system_first_name%"
So I thought it would work, but it is not. When I execute it like this:
database_cursor.execute(customer_information_SQLString + SQL_where, parameters)
I get this:
ProgrammingError: ('The SQL contains 2 parameter markers, but 1 parameters were supplied', 'HY000')
Does anyone know how to handle this?