Feb-11-2019, 09:33 PM
if name and month and year: 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) ) print( 1 ) elif name and year: cur.execute( '''SELECT * FROM jobs WHERE clientID = (SELECT id FROM clients WHERE name = %s) and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (name, year) ) print( 2 ) elif month and year: cur.execute( '''SELECT * FROM jobs WHERE MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (month, year) ) print( 3 ) elif year: cur.execute( '''SELECT * FROM jobs WHERE YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', year ) print( 4 )Its almost correct except the fast that the last "elif" never gets executed. Even if 'month=0', which mean no selection of month still this clause 'elif month and year:' always executes instead of the last one.
Please can someone correct this and explain why?
Thank you!