Answers.Body: <p>I have the same problem. I have some installations that work correctly and some that's don't work.</p>
  
  <p>I made this patch, it's not a nice patch, becasuse it's not applied in CRM_Contact_Form_Search_Builder, but temporally works</p>
  
  <p><a href="https://github.com/rubofvil/civicrm-core/commit/facfa396891229eb914397eb4920e75b6abff4a2" rel="nofollow">https://github.com/rubofvil/civicrm-core/commit/facfa396891229eb914397eb4920e75b6abff4a2</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-05T10:53:54.547Z
Answers.LastActivityDate: 2016-05-05T10:53:54.547Z
Answers.UserDisplayName: rubofvil
Answers.Body: <p>For completeness, my comment probably should have been an answer…</p>
  
  <p>I think this is probably a bug. </p>
  
  <p>It doesn't matter if you create a new location type or use a pre-populated one. The sql has a column that doesn't exists and it's going against the wrong table. 
  Here's the sql: </p>
  
  <pre><code>SELECT DISTINCT UPPER(LEFT(contact_a.sort_name, 1)) as sort_name 
  FROM   civicrm_contact contact_a 
  WHERE  ( ( LOWER(Home-location_type.name) = '8' ) ) 
  AND    (contact_a.is_deleted = 0) GROUP BY contact_a.id 
  ORDER BY UPPER(LEFT(contact_a.sort_name, 1)) asc 
  </code></pre>
  
  <p>[nativecode=1054 ** Unknown column 'Home-location_type.name' in 'where clause'" </p>
  
  <p>AlanGallery submitted a bug see comment above.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-20T15:26:44.833Z
Answers.LastActivityDate: 2015-10-20T15:26:44.833Z
Answers.UserDisplayName: Paul-Tahoe
Body: <p>On current CiviCRM demo site (4.6.10) if you</p>
  
  <p>add a new location type, then populate a contact with an email address of that location type, then use Search builder to search for email address with location type, it gives error:</p>
  
  <p>DB Error: syntax error</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-20T00:48:08.213Z
Comments.Text: I think this is probably a bug.  It doesn't matter if you create a new location type or use a pre-populated one.  The sql has a column that doesn't exists and it's going against the wrong table.  Here's the sql:  SELECT DISTINCT UPPER(LEFT(contact_a.sort_name, 1)) as sort_name FROM civicrm_contact contact_a WHERE ( ( LOWER(`Home-location_type`.name) = '8' ) ) AND (contact_a.is_deleted = 0) GROUP BY contact_a.id ORDER BY UPPER(LEFT(contact_a.sort_name, 1)) asc [nativecode=1054 ** Unknown column 'Home-location_type.name' in 'where clause'" Can you file a bug?
Comments.UserDisplayName: Paul-Tahoe
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-20T14:21:36.480Z
Comments.Text: Thanks Paul-Tahoe, I've submitted as a bug: https://issues.civicrm.org/jira/browse/CRM-17424
Comments.UserDisplayName: AlanGallery
Tags: <search><location-type>
Title: Using Search Builder to search on a field with custom location gives DB error
ThreadText: # Using Search Builder to search on a field with custom location gives DB error
  
  (Asked by: username_0 on 2015-10-19)
  
  On current CiviCRM demo site (4.6.10) if you
  
  add a new location type, then populate a contact with an email address of that location type, then use Search builder to search for email address with location type, it gives error:
  
  DB Error: syntax error
  
  **Tags:** search, location-type
  
  > **Comments:**
  > **username_1**: I think this is probably a bug.  It doesn't matter if you create a new location type or use a pre-populated one.  The sql has a column that doesn't exists and it's going against the wrong table.  Here's the sql:  SELECT DISTINCT UPPER(LEFT(contact_a.sort_name, 1)) as sort_name FROM civicrm_contact contact_a WHERE ( ( LOWER(`Home-location_type`.name) = '8' ) ) AND (contact_a.is_deleted = 0) GROUP BY contact_a.id ORDER BY UPPER(LEFT(contact_a.sort_name, 1)) asc [nativecode=1054 ** Unknown column 'Home-location_type.name' in 'where clause'" Can you file a bug?  
  > **username_0**: Thanks username_1, I've submitted as a bug: https://issues.civicrm.org/jira/browse/CRM-17424  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-05-05. Score: 1
  
  I have the same problem. I have some installations that work correctly and some that's don't work.
  
  I made this patch, it's not a nice patch, becasuse it's not applied in CRM\_Contact\_Form\_Search\_Builder, but temporally works
  
  <https://github.com/username_2/civicrm-core/commit/facfa396891229eb914397eb4920e75b6abff4a2>
  
  
  ---
  
  ### Answer by username_1 on 2015-10-20. Score: 1
  
  For completeness, my comment probably should have been an answer…
  I think this is probably a bug. 
  It doesn't matter if you create a new location type or use a pre-populated one. The sql has a column that doesn't exists and it's going against the wrong table. 
  Here's the sql: 
  SELECT DISTINCT UPPER(LEFT(contact_a.sort_name, 1)) as sort_name 
  FROM   civicrm_contact contact_a 
  WHERE  ( ( LOWER(Home-location_type.name) = '8' ) ) 
  AND    (contact_a.is_deleted = 0) GROUP BY contact_a.id 
  ORDER BY UPPER(LEFT(contact_a.sort_name, 1)) asc 
  
  [nativecode=1054 ** Unknown column 'Home-location_type.name' in 'where clause'" 
  username_0 submitted a bug see comment above.
  
  
  ---
  
  