title: Add filter only if the variable is given with values in Metabase
body: <p>In Metabase, one can add variables with <code>{{variable}}</code> in queries, such as:</p>
  
  <pre><code>select *
  from dashboard_demographic_view
  where clinic_id = {{clinic}}
  </code></pre>
  
  <p>, where <code>dashboard_demographic_view</code> is a view created in advance. In the query above, rows where <code>clinic_id</code> matches what is given in <code>{{clinic}}</code> will be returned.</p>
  
  <p>Still, I am curious what if I need that filter only when I give <code>{{clinic}}</code> a value, or otherwise the query should return all the rows. I've referred to <a href="https://stackoverflow.com/questions/38828272/sql-add-filter-only-if-a-variable-is-not-null">SQL add filter only if a variable is not null</a> but it is not helping in my case.</p>
  
  <pre><code>select *
  from dashboard_demographic_view
  where ({{clinic}} is null or clinic_id = {{clinic}})
  </code></pre>
  
  <p>The query above gives <em>Unable to substitute 'clinic': param not specified. Found: ("clinic")</em> when I don't specify <code>clinic</code>.</p>
  
  <p>Theoretically this can be solved by making the variable <code>{{clinic}}</code> a field filter. However, for some reasons that cannot be done for a view (<a href="https://github.com/metabase/metabase/issues/8800" rel="nofollow noreferrer">#8800 in metabase</a>).</p>
  
  <p>I am seeking workarounds other than making a real table to fulfill my purposes. Any help would be appreciated.</p>