I'm having this situation to check whether an account number exists in a row in database. The column can contain a number of account numbers each separated by a comma eg. 00001,00002,00003.
eg case:SELECT * FROM finance_collection.member WHERE account_ids LIKE 00001,% OR %,00001 OR %,00001,% OR 00001
For this I wrote an SQL statement as:
account_exists = " SELECT * FROM finance_collection.member WHERE account_ids LIKE %s,% OR %,%s OR %,%s,% OR %s "
Here %s is the incoming account number , is a comma and % is a multicharacter wildcard.
try:
with connection.cursor() as cursor:
sql = sqls.account_exists
cursor.execute(sql, (account, account, account, account))
return True
except pymysql.Error as error:
print(error)
return False
I'm using pymysql to connect and it seems the query isn't working. I tried various combinations like surrounding %s,% with ' ' and others but none of them worked. Can you show me a light here?
%to escape them.TypeError: not enough arguments for format string