On Sun, 7 Oct 2001 19:24:42 -0400, "Aaron Held" <[EMAIL PROTECTED]> wrote: > >I hate the >SQL += 'WHERE 1=1 AND' >if (DateRange): > SQL += ' ( (callDate > %(startDate)s) AND (callDate > %(endDate)s) ) ' >if (OneDate): > SQL +=' callDate = %(startDate)s' > >Currenly I write this code over and over in PHP programs and I am migrating >to python to clean up the code. I always thought this was ugly.
I find it clearer to create a list of subclauses, and use join to build the larger clause: where = [] if DateRange: where.append( 'callDate >= %s' % startDate ) where.append( 'callDate < %s' % startDate ) if OneDate: where.append( 'callDate = %s' % startDate ) ... other where.append ... sql += 'where (' + ') and ('.join(where) + ')' -- - Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. _______________________________________________ Webware-discuss mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/webware-discuss