diff --git a/app/models/query.rb b/app/models/query.rb index f41c1cdaa..0f1404745 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -367,7 +367,7 @@ class Query < ActiveRecord::Base index = (index ? index + 1 : -1) # insert the column after estimated_hours or at the end @available_columns.insert index, QueryColumn.new(:spent_hours, - :sortable => "(SELECT SUM(hours) FROM #{TimeEntry.table_name} WHERE #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id)", + :sortable => "(SELECT COALESCE(SUM(hours), 0) FROM #{TimeEntry.table_name} WHERE #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id)", :default_order => 'desc', :caption => :label_spent_time )