duration_sql = (
    'select MessageTime, Value from [%s] where Subsystem=%s and Field=%s and MessageTime > %s and MessageTime < %s'
     % (i, j, k, l, m))
Assembling a long string with parameters in python