title: Conditional Binding in SPARQL/CONSTRUCT
body: <p>I have a SPARQL CONSTRUCT that works like this: </p>
  
  <pre><code>CONSTRUCT {
    ?uri rdfs:label ?label; 
         foo:has-value ?v.        
  }
  WHERE {
    ?uri 
       rdfs:label ?label; 
       foo:has-flag ?f.
  
    BIND ( IF ( ?f = 0, "Value for Zero", IF ( ?f = 1, "Value for One", '' ) ) AS ?v )
  }
  </code></pre>
  
  <p>The problem is that when <code>?f</code> is neither 0 nor 1 (but still has some value) I don't want the <code>has-value</code> statement at all. With the syntax above, I get <code>?uri has-value ''</code>. It would work, if I could assign some sort of "null" to <code>?v</code>, or avoid the binding, but I cannot find anything like that in the specs.</p>
  
  <p>Any solution?</p>
  
  <p><strong>EDIT</strong>: The <a href="https://stackoverflow.com/a/42462762/529286">solution by Scott</a> works for common graph-based queries. The case I came from involves the use of VALUES, <a href="http://jena.markmail.org/search/#query:%20list%3Aorg.apache.incubator.jena-dev+page:1+mid:q3fp3ve3dgolc2cz+state:results" rel="nofollow noreferrer">is more complicated</a> and I couldn't find a solution so far.</p>
  
  <p><strong>EDIT/2</strong>: the <a href="http://jena.markmail.org/search/#query:%20list%3Aorg.apache.incubator.jena-dev+page:1+mid:q3fp3ve3dgolc2cz+state:results" rel="nofollow noreferrer">error-triggering solution</a>, suggested by Andy in the Jena mailing list, works fine! Another approach, which I find more readable, is <a href="https://github.com/tarql/tarql/issues/55" rel="nofollow noreferrer">binding an unbound variable</a> when we want to skip the original value. </p>