Customize a View 3 SQL query I've created a view that lists the content based on the first letter of that title matching an argument passed to the page. Now I'm trying to do the same, but with a 0-9 so when the user selects 0-9 the view gets all content types which begin with a number in the range 0-9.

I'm currently looking at hook_views_query_alter(), but I don't get back the results I am expecting. The function I've written is the following one:

function module_views_query_alter(&amp;$view, &amp;$query) {
  if ($view-&gt;name == 'custom_page' &amp;&amp; $view-&gt;current_display == 'page_1') {
    if ($view-&gt;args[0] == '0-9') {
      $query-&gt;where[0]['conditions'][2]['field'] = 'SUBSTRING(node.title, 1, 1)';
      $query-&gt;where[0]['conditions'][2]['value'] = array('0','1','2','3','4','5','6','7','8','9');
      $query-&gt;where[0]['conditions'][2]['operator'] = 'in';
    }
  }
}
This is a bit of a cheat following the code that's used by the glossary view, but it works:

function module_views_query_alter(&amp;$view, &amp;$query) {
  if ($view-&gt;name == 'custom_page' &amp;&amp; $view-&gt;current_display == 'page_1') {
    if ($view-&gt;args[0] == '0-9') {
      $query-&gt;where[0]['conditions'][2]['field'] =  "SUBSTRING(node.title, 1, :node_title) in ('0','1','2','3','4','5','6','7','8','9')";
      $query-&gt;where[0]['conditions'][2]['value'] = array(':node_title' =&gt; 1);
      $query-&gt;where[0]['conditions'][2]['operator'] = 'formula';
    }