MSSQL Incompatibility with Organic Group Views Filter Handlers I have a view which filters all the organic groups for a user. I wanted to add a Views Filter to filter by OG Role, however it is not possible.

I would very much appreciate any help. Basically any OG Role filter using a Views Filter Handler cannot be used if the database is an MSSQL database. When selecting one of the filters, it errors out and then the view has to be re-created since the view can no longer be shown within the UI. I opened a drupal issue a few months ago, but no response as of yet.

The error message is as follows:


  PDOException: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Column 'og_role.rid' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.: SELECT r.*, r.name AS _field_0 FROM {og_role} r GROUP BY r.name; Array ( ) in og_handler_filter_user_roles-&gt;get_value_options() (line 14 of C:\inetpub\wwwroot\sites\all\modules\og\includes\views\handlers\og_handler_filter_user_roles.inc).


I'm almost postive that I have to rewrite Line 13 to support SQLSRV database types.

Line 13: -&gt;groupBy('r.name')

Here is the relevant code:

/**
 * Field handler to provide a list of OG roles of a user.
 */
class og_handler_filter_user_roles extends views_handler_filter_many_to_one {

  function get_value_options() {
    $this-&gt;value_options = array();
    // Get all role names.
    $results = db_select('og_role', 'r')
      -&gt;fields('r')
      -&gt;groupBy('r.name')
      -&gt;execute();
    foreach ($results as $result) {
      $this-&gt;value_options[$result-&gt;name] = $result-&gt;name;
    }
  }

  function query() {
    // Get the og_membership table from relations.
    foreach ($this-&gt;query-&gt;relationships as $alias =&gt; $info) {
      if ($info['table'] == 'og_membership') {
        // If there is a og_membership table present. Add some conditions.
        $rel = $this-&gt;relationship;
        $this-&gt;query-&gt;add_where_expression(NULL, $alias . '.gid = ' . $rel . '.gid');
        $this-&gt;query-&gt;add_where_expression(NULL, $alias . '.group_type = ' . $rel . '.group_type');
        break;
      }
    }

    parent::query();
  }
}
I fixed it by changing Line 13 to:

-&gt;groupBy('r.name')
-&gt;groupBy('r.rid')
-&gt;groupBy('r.gid')
-&gt;groupBy('r.group_type')
-&gt;groupBy('r.group_bundle')