Feb-09-2019, 11:52 PM
This does not work well some parts of if work and some others don't:
if name and month.isdigit() and year.isdigit(): cur.execute( '''SELECT * FROM jobs WHERE clientID = (SELECT id FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (name, month, year) ) elif name and year.isdigit(): cur.execute( '''SELECT * FROM jobs WHERE clientID = (SELECT id FROM clients WHERE name = %s) and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (name, year) ) elif month.isdigit() and year.isdigit(): cur.execute( '''SELECT * FROM jobs WHERE MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (month, year) ) elif year.isdigit(): cur.execute( '''SELECT * FROM jobs WHERE YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', year )Please helpe me write it correctly and simply.