title: How to Ignore Null Parameters in SQL Query
body: <p>Well I have a problem, and I don't even know that what I'm trying or thinking to do is possible or not.</p>
  
  <p>I have a sql query:-</p>
  
  <pre><code> select * 
   from table
   where (col1 &gt;= '2016-07-05' and col2 &lt;= '2016-07-07')
   and col3 = '' 
   and col4 = ''
   and col5 = ''
   and col6 = '686486'
   and col7 = ''
   and col8 = '';
  </code></pre>
  
  <p>Ok I'm using this query to perform a search operation, i want it to be very specific that's why i'm thinking of doing it this way.</p>
  
  <p>All these parameters can be null or can have any value, So all i want is to ignore those paramters whose value is null.</p>
  
  <p>For Eg:- For above query the result should be same as</p>
  
  <pre><code> select * 
   from vehicle
   where (col1 &gt;= '2016-07-05' and col2 &lt;= '2016-07-07')
   and col6 = '686486'; 
  </code></pre>
  
  <p>Edit 1: First of all thanks for helping me out,I tried what was suggested</p>
  
  <pre><code> select * 
   from table
   where (('val1' is null or col1 &gt;= 'val1') and ('val2' is null or col2 &lt;= 
    'val2'))
   and ('val3' is null or col3 = 'val3')
   and ('val4' is null or col4 = 'val4')
   and ('val5' is null or col5 = 'val5')
   and ('val6' is null or col6 = 'val6')
   and ('val7' is null or col7 = 'val7')
   and ('val8' is null or col8 = 'val8');
  </code></pre>
  
  <p>But I'm getting 0 rows as a result for this query, Am I doing something wrong.</p>