title: What is the best-practice for nesting PreparedStatements?
body: <p>I have several instances where that a section of legacy sql statements is based on a dependency. for example. </p>
  
  <pre><code>if (x !=null)
  {
    SQL = "SELECT z WHERE x &gt; y";
  }
  else
  {
    SQL = "SELECT z WHERE x &lt;= y";
  } 
  
  SQL2 = SQL + " JOIN a ON b";
  </code></pre>
  
  <p>I am creating PreparedStatements out of this legacy code. What is the best-practice here. Should I create a PreparedStatement for the var SQL and nest it inside of SQL2 of should there be multiple PreparedStatements based on SQL2 without nesting, or something totlly different?  </p>
  
  <p>The code is much more complex than the example, as the SQL var is reused inside many long and complex SQL queries.</p>
  
  <p>EDIT: Project Design requires using PreparedStatements, I don't have the choice of using libraries at this moment.</p>