title: Omit one of the many where conditions if a constant is a specific value
body: <p>I am pulling records from a SQL Server from python:</p>
  
  <pre><code>REGION = 'HK'
  .
  .
      where   
  
                  R.rfq_create_date_time &gt;= '""" + START_DATE + """'
                  and R.rfq_create_date_time &lt;= '""" + END_DATE + """'
                  and R.latest_version = 'Y' 
                  and R.sales_book in ('""" + sales_code_string + """')
                  and R.Trading_book in ('""" + Trading_Books + """')
                  ) as innerTable 
                  WHERE rfq_create_time not between '""" + START_TIME + """' and '""" + END_TIME + """'
                  order by rfq_create_time"""
  
      print (strSql)
      print("")
      df_With_NaN = pd.read_sql(strSql, pyodbc.connect(connstr))
  </code></pre>
  
  <p>I only want the <code>and R.Trading_book in</code> condition included in the string to pass to my connection if <code>REGION</code> is HK or SY. In the case of TK I want the condition ignored all together.</p>
  
  <p>Is the replace method the best way to do this in python or is there an alterantive? For example:</p>
  
  <pre><code>REGION = "TK"
  strsql = "select * from table where ccy = 'AAA' ######"
  if REGION == "HK":
      booklist = "'AAA','BBB','CCC'"
  elif REGION == "SY":
      booklist = "'CCC','DDD','FFF'"
  
  if REGION == "TK":
      strsql = strsql.replace("######", "")
  else:
      strsql = strsql.replace("######", " and book in (" + booklist + ")")
  
  print (strsql)
  </code></pre>