On 6 March 2012 15:08, John Merlino <[email protected]> wrote:
> Hey all,
>
> So I have a custom query that I embedded into a class method
> definition:
>
>
> def self.get_sum_for_range(unit_id,report1,report2)
>     find_by_sql(["SELECT SUM(distance * 0.000621371192) as sum FROM
> reports WHERE unit_id=? AND id >= ? AND id <= ?", unit_id, report1,
> report2])

Not related directly to your question but I feel I should point out
that there is almost certainly something wrong with your database
design if you are using id values to select a range of records.  It is
not a good idea to use id values for anything other than being a
unique value for each record.  If you need something like a
report_number to be used in the way you are doing here it is generally
better to add an extra column for that.  Suppose for example that
while adding reports you missed one out, using the id there would be
no way of going back and inserting one in the range later.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to