Answers.Body: <p>Further investigation found that this was failing not only with <code>contribution_source</code>, but also for <code>financial_type</code> and <code>contribution_status</code>.</p>
  
  <p>A fix has been raised to address this issue at <a href="https://github.com/civicrm/civicrm-core/pull/9516" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/pull/9516</a>. It'll be included in 4.7.15.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-09T08:45:58.010Z
Answers.LastActivityDate: 2016-12-09T08:45:58.010Z
Answers.UserDisplayName: jitendra - fuzion
Answers.Body: <p>In contribution you don't have a column called <strong>contribution_source</strong>. so, please change the column name to <strong>source</strong> also you are not using alise for the column use <strong>civicrm_contribution.source</strong></p>
  
  <p>Please try the below SQL: I guess that should work </p>
  
  <p>SELECT civicrm_contribution.id, contact_a.id as contact_id, civicrm_contribution.id as contribution_id, civicrm_contribution.contribution_status_id as contribution_status_id 
  FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id 
  WHERE ( ( civicrm_contribution.receive_date >= '20161017000000' ) AND ( civicrm_contribution.receive_date &lt;= '20161018235959' ) 
  AND civicrm_contribution.financial_type_id IN ("5", "1", "4") 
  AND civicrm_contribution.financial_type_id IN ("1") 
  AND civicrm_contribution.contribution_status_id IN ("1") 
  AND civicrm_contribution.thankyou_date IS NULL AND civicrm_contribution.is_test = 0 ) 
  AND (contact_a.is_deleted = 0) 
  GROUP BY civicrm_contribution.id 
  ORDER BY civicrm_contribution.source desc, contact_a.id </p>
  
  <p>I guess this helps !!!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-04T00:36:03.813Z
Answers.Text: Ramesh, I wonder where we should try making this change.
  
  The fatal error happens when we're using Civi's web interface, with that SQL that's throwing the fatal error generated by Civi's code.
Answers.UserDisplayName: galgeek
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-06T03:41:47.643Z
Answers.Text: Please try to reproduce the same issue against CiviCRM Demo - If you couldn't reproduce the issue then please try to upgrade your local CiviCRM code base - That should Fix..
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-19T08:50:18.420Z
Answers.LastActivityDate: 2016-10-19T08:50:18.420Z
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Body: <p>When we use Find Contributions to generate a list of contributions for thank you e-mails, then select the All Records radio button, and then choose Thank You Letters, we see the fatal error below.</p>
  
  <p>I do see code in CRM/Contribute/Form/Task/Batch.php that looks like it's meant to handle an issue like this: <a href="https://github.com/civicrm/civicrm-core/blob/67ea385e0e5cd3daed04807c1465605f059b1002/CRM/Contribute/Form/Task/Batch.php#L230" rel="nofollow">https://github.com/civicrm/civicrm-core/blob/67ea385e0e5cd3daed04807c1465605f059b1002/CRM/Contribute/Form/Task/Batch.php#L230</a></p>
  
  <p>We do <em>not</em> get the fatal error when we use the select all <em>checkbox</em> instead of the All Records radio button.</p>
  
  <p>I have not yet been able to replicate on the demo. (The CiviHosting Drupal 7 demo is throwing an error right now itself.)</p>
  
  <pre><code>$Fatal Error Details = Array ( 
  [callback] =&gt; Array ( [0] =&gt; CRM_Core_Error [1] =&gt; handle ) 
  [code] =&gt; -19 [message] =&gt; DB Error: no such field [mode] =&gt; 16     
  [debug_info] =&gt; 
  SELECT civicrm_contribution.id, contact_a.id as contact_id, 
  civicrm_contribution.id as contribution_id,
  civicrm_contribution.contribution_status_id as `contribution_status_id` 
  FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON 
  civicrm_contribution.contact_id = contact_a.id WHERE ( ( 
  civicrm_contribution.receive_date &gt;= '20161017000000' ) AND ( 
  civicrm_contribution.receive_date &lt;= '20161018235959' ) AND 
  civicrm_contribution.financial_type_id IN ("5", "1", "4") AND 
  civicrm_contribution.financial_type_id IN ("1") AND 
  civicrm_contribution.contribution_status_id IN ("1") AND 
  civicrm_contribution.thankyou_date IS NULL AND 
  civicrm_contribution.is_test = 0 ) AND 
  (contact_a.is_deleted = 0) 
  GROUP BY civicrm_contribution.id 
  ORDER BY `contribution_source` desc, 
  `contact_a`.`id` [
  nativecode=1054 ** Unknown column 'contribution_source' in 'order clause'] 
  [type] =&gt; DB_Error 
  [user_info] =&gt; 
  SELECT civicrm_contribution.id, contact_a.id as contact_id, 
  civicrm_contribution.id as contribution_id, 
  civicrm_contribution.contribution_status_id as `contribution_status_id` 
  FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON 
  civicrm_contribution.contact_id = contact_a.id WHERE ( ( 
  civicrm_contribution.receive_date &gt;= '20161017000000' ) AND ( 
  civicrm_contribution.receive_date &lt;= '20161018235959' ) AND 
  civicrm_contribution.financial_type_id IN ("5", "1", "4") AND 
  civicrm_contribution.financial_type_id IN ("1") AND 
  civicrm_contribution.contribution_status_id IN ("1") AND 
  civicrm_contribution.thankyou_date IS NULL AND 
  civicrm_contribution.is_test = 0 ) AND
  (contact_a.is_deleted = 0) 
  GROUP BY civicrm_contribution.id 
  ORDER BY `contribution_source` desc, 
  `contact_a`.`id` 
  [nativecode=1054 ** Unknown column 'contribution_source' in 'order clause'] [to_string] =&gt; [db_error: message="DB Error: no such field" code=-19 mode=callback callback=CRM_Core_Error::handle prefix="" info="SELECT civicrm_contribution.id, contact_a.id as contact_id, civicrm_contribution.id as contribution_id, civicrm_contribution.contribution_status_id as `contribution_status_id` FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id WHERE ( ( civicrm_contribution.receive_date &gt;= '20161017000000' ) AND ( civicrm_contribution.receive_date &lt;= '20161018235959' ) AND civicrm_contribution.financial_type_id IN ("5", "1", "4") AND civicrm_contribution.financial_type_id IN ("1") AND civicrm_contribution.contribution_status_id IN ("1") AND civicrm_contribution.thankyou_date IS NULL AND civicrm_contribution.is_test = 0 ) AND (contact_a.is_deleted = 0) GROUP BY civicrm_contribution.id ORDER BY `contribution_source` desc, `contact_a`.`id` [nativecode=1054 ** Unknown column 'contribution_source' in 'order clause']"] )
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-19T09:02:26.837Z
Comments.Text: sorry for the below answer - please let me know how to recreate the issue - i dont see a radio button in batch export
Comments.UserDisplayName: Ramesh - ARTECH Consultancy
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-19T15:44:57.277Z
Comments.Text: I looked into this per our discussion on chat.civicrm.org yesterday - but I'm not sure how to replicate this.  Could you please update the question to explain what steps you took to cause this?  Do you experience the same issue on the demo server?
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-24T01:34:03.437Z
Comments.Text: Thank you for taking a look! I've added the requested details above.
Comments.UserDisplayName: galgeek
Tags: <civicontribute>
Title: fatal error: Unknown column 'contribution_source' in 'order clause'
ThreadText: # fatal error: Unknown column 'contribution_source' in 'order clause'
  
  (Asked by: username_0 on 2016-10-18)
  
  When we use Find Contributions to generate a list of contributions for thank you e-mails, then select the All Records radio button, and then choose Thank You Letters, we see the fatal error below.
  I do see code in CRM/Contribute/Form/Task/Batch.php that looks like it's meant to handle an issue like this: https://github.com/civicrm/civicrm-core/blob/67ea385e0e5cd3daed04807c1465605f059b1002/CRM/Contribute/Form/Task/Batch.php#L230
  We do not get the fatal error when we use the select all checkbox instead of the All Records radio button.
  I have not yet been able to replicate on the demo. (The CiviHosting Drupal 7 demo is throwing an error right now itself.)
  $Fatal Error Details = Array ( 
  [callback] => Array ( [0] => CRM_Core_Error [1] => handle ) 
  [code] => -19 [message] => DB Error: no such field [mode] => 16     
  [debug_info] => 
  SELECT civicrm_contribution.id, contact_a.id as contact_id, 
  civicrm_contribution.id as contribution_id,
  civicrm_contribution.contribution_status_id as `contribution_status_id` 
  FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON 
  civicrm_contribution.contact_id = contact_a.id WHERE ( ( 
  civicrm_contribution.receive_date >= '20161017000000' ) AND ( 
  civicrm_contribution.receive_date <= '20161018235959' ) AND 
  civicrm_contribution.financial_type_id IN ("5", "1", "4") AND 
  civicrm_contribution.financial_type_id IN ("1") AND 
  civicrm_contribution.contribution_status_id IN ("1") AND 
  civicrm_contribution.thankyou_date IS NULL AND 
  civicrm_contribution.is_test = 0 ) AND 
  (contact_a.is_deleted = 0) 
  GROUP BY civicrm_contribution.id 
  ORDER BY `contribution_source` desc, 
  `contact_a`.`id` [
  nativecode=1054 ** Unknown column 'contribution_source' in 'order clause'] 
  [type] => DB_Error 
  [user_info] => 
  SELECT civicrm_contribution.id, contact_a.id as contact_id, 
  civicrm_contribution.id as contribution_id, 
  civicrm_contribution.contribution_status_id as `contribution_status_id` 
  FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON 
  civicrm_contribution.contact_id = contact_a.id WHERE ( ( 
  civicrm_contribution.receive_date >= '20161017000000' ) AND ( 
  civicrm_contribution.receive_date <= '20161018235959' ) AND 
  civicrm_contribution.financial_type_id IN ("5", "1", "4") AND 
  civicrm_contribution.financial_type_id IN ("1") AND 
  civicrm_contribution.contribution_status_id IN ("1") AND 
  civicrm_contribution.thankyou_date IS NULL AND 
  civicrm_contribution.is_test = 0 ) AND
  (contact_a.is_deleted = 0) 
  GROUP BY civicrm_contribution.id 
  ORDER BY `contribution_source` desc, 
  `contact_a`.`id` 
  [nativecode=1054 ** Unknown column 'contribution_source' in 'order clause'] [to_string] => [db_error: message="DB Error: no such field" code=-19 mode=callback callback=CRM_Core_Error::handle prefix="" info="SELECT civicrm_contribution.id, contact_a.id as contact_id, civicrm_contribution.id as contribution_id, civicrm_contribution.contribution_status_id as `contribution_status_id` FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id WHERE ( ( civicrm_contribution.receive_date >= '20161017000000' ) AND ( civicrm_contribution.receive_date <= '20161018235959' ) AND civicrm_contribution.financial_type_id IN ("5", "1", "4") AND civicrm_contribution.financial_type_id IN ("1") AND civicrm_contribution.contribution_status_id IN ("1") AND civicrm_contribution.thankyou_date IS NULL AND civicrm_contribution.is_test = 0 ) AND (contact_a.is_deleted = 0) GROUP BY civicrm_contribution.id ORDER BY `contribution_source` desc, `contact_a`.`id` [nativecode=1054 ** Unknown column 'contribution_source' in 'order clause']"] )
  
  **Tags:** civicontribute
  
  > **Comments:**
  > **username_1**: sorry for the below answer - please let me know how to recreate the issue - i dont see a radio button in batch export  
  > **username_2**: I looked into this per our discussion on chat.civicrm.org yesterday - but I'm not sure how to replicate this.  Could you please update the question to explain what steps you took to cause this?  Do you experience the same issue on the demo server?  
  > **username_0**: Thank you for taking a look! I've added the requested details above.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2016-12-09. Score: 2
  
  Further investigation found that this was failing not only with `contribution_source`, but also for `financial_type` and `contribution_status`.
  
  A fix has been raised to address this issue at <https://github.com/civicrm/civicrm-core/pull/9516>. It'll be included in 4.7.15.
  
  
  ---
  
  ### Answer by username_1 on 2016-10-19. Score: 0
  
  In contribution you don't have a column called **contribution\_source**. so, please change the column name to **source** also you are not using alise for the column use **civicrm\_contribution.source**
  
  Please try the below SQL: I guess that should work
  
  SELECT civicrm\_contribution.id, contact\_a.id as contact\_id, civicrm\_contribution.id as contribution\_id, civicrm\_contribution.contribution\_status\_id as contribution\_status\_id
  FROM civicrm\_contact contact\_a LEFT JOIN civicrm\_contribution ON civicrm\_contribution.contact\_id = contact\_a.id
  WHERE ( ( civicrm\_contribution.receive\_date >= '20161017000000' ) AND ( civicrm\_contribution.receive\_date <= '20161018235959' )
  AND civicrm\_contribution.financial\_type\_id IN ("5", "1", "4")
  AND civicrm\_contribution.financial\_type\_id IN ("1")
  AND civicrm\_contribution.contribution\_status\_id IN ("1")
  AND civicrm\_contribution.thankyou\_date IS NULL AND civicrm\_contribution.is\_test = 0 )
  AND (contact\_a.is\_deleted = 0)
  GROUP BY civicrm\_contribution.id
  ORDER BY civicrm\_contribution.source desc, contact\_a.id
  
  I guess this helps !!!
  
  > **Comments:**
  > **username_0**: Ramesh, I wonder where we should try making this change.  The fatal error happens when we're using Civi's web interface, with that SQL that's throwing the fatal error generated by Civi's code.  
  > **username_1**: Please try to reproduce the same issue against CiviCRM Demo - If you couldn't reproduce the issue then please try to upgrade your local CiviCRM code base - That should Fix..  
  
  ---
  
  