Custom SQL query in views 3

Events happening in the community are now at Drupal community events on www.drupal.org.
jmolinas's picture

I'am currently doing a project involving cck and views, Sometimes you can’t always get the things you want by using views, so I came across this when i was looking for a way to use my own sql queries in combination with views. I created custom module just for my custom sql queries using this code seem to work with view 2 but not for views 3. Are there any changes is views api?

function custom_views_views_pre_execute(&$view) {

if($view->name=="sales_report_dev")
    {
     $view->build_info['query']=
  "SELECT node.nid AS nid,
users.name AS users_name,
users.uid AS users_uid, SUM(node_data_field_sales_date.field_sales_quantity_value) AS node_data_field_sales_date_field_sales_quantity_value,
  node.type AS node_type, node.vid AS node_vid FROM node node  LEFT JOIN content_type_sales_report node_data_field_sales_date ON node.vid = node_data_field_sales_date.vid INNER JOIN users users ON node.uid = users.uid
   WHERE (node.type in ('sales_report')) GROUP BY users.name
    ";

  

}

Thanks

Comments

Change of Approach

killer_tilapia's picture

You could just directly access the Drupal DB rather than deal with Views. Please see http://api.drupal.org/api/drupal/includes--database--database.inc/group/...

Actually I also tried SQL

jmolinas's picture

Actually I also tried SQL queries, but can i also use it with exposed filters?

Philippines

Group organizers

Group categories

Post category

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: