title: Building dynamic where condition in SQL statement
body: <p>I want to build custom Where condition based on stored procedure inputs, if not null then I will use them in the statement, else I will not use them.</p>
  
  <pre><code>if @Vendor_Name is not null
      begin 
  
      set @where += 'Upper(vendors.VENDOR_NAME) LIKE "%"+ UPPER(@Vendor_Name) +"%"'
  
      end
      else if @Entity is not null
      begin
      set @where += 'AND headers.ORG_ID = @Entity'
      end
  select * from table_name where @where
  </code></pre>
  
  <p>But I get this error</p>
  
  <pre><code>An expression of non-boolean type specified in a context where a condition is expected, near 'set'.
  </code></pre>