Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with and if() logic
#1
		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!
Reply


Messages In This Thread
Problem with and if() logic - by nikos - Feb-11-2019, 09:33 PM
RE: Problem with and if() logic - by nilamo - Feb-11-2019, 09:54 PM
RE: Problem with and if() logic - by nikos - Feb-11-2019, 10:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem in formulating append logic shantanu97 1 1,035 Jun-07-2022, 08:35 AM
Last Post: ibreeden
  Number logic problem m1xzg 13 10,704 Oct-23-2016, 09:36 PM
Last Post: m1xzg

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020