title: Dynamic SOQL Query
body: <p>I'm trying this code for dynamic results but it's showing the error shown below. Kindly help me with this code.</p>
  
  <blockquote>
    <p>System.QueryException: Only variable references are allowed in dynamic SOQL/SOSL.</p>
  </blockquote>
  
  <pre><code>      boolean first = true;
        string database_query = '';
         List&lt;Schema.FieldSetMember&gt; userfields = SObjectType.Task__c.FieldSets.Search.getFields();
       for(Schema.FieldSetMember f : userfields) {  
          if (!first) {
                 database_query += ', ';                
           }
           first = false;
           database_query += f.getFieldPath(); 
       }
      if(Search_value != '' &amp;&amp; database_query != ''){           
        TaskList  = Database.query('select ' + database_query +',SOE__c from task__c where SOE__c =: \''+selectSOE +'\' and '+ selectedfield + ' like \'%' + Search_value +'%\'');           
      }
  </code></pre>