hi, Im running the following sql statment which returns 1 result. pSql = "SELECT sum(amount) FROM payments WHERE expected_pay_date LIKE ''"+pWholeDate+"%'' AND invoice_id IS null " aResult = Payment.find_by_sql(pSql) how can I get the result of this? (when doing @aResult.inspect it returns [#"18001.25"}>]) thanks scott -- Posted via http://www.ruby-forum.com/.
ben wrote:> hi, > > Im running the following sql statment which returns 1 result. > > pSql = "SELECT sum(amount)my guess is that the result [#"18001.25"] is the result of the sum() function you propagated in the sql statement - - you took what you want to be aResult, and added them altogether to eventually add up to 18001.25 (which is the correct output for the sql-query) i don''t really know what you have in your table, but what about taking out the amount of each row, and then in the view/controller do a sum action (if you need to)? in order to get aResult, just change SELECT sum(amount) ... to SELECT amount ... don''t know if it will fit your needs , but is it helping...? -- Posted via http://www.ruby-forum.com/.
On 7/5/06, ben <ben@streamd.com> wrote:> > hi, > > Im running the following sql statment which returns 1 result. > > pSql = "SELECT sum(amount) > FROM payments > WHERE expected_pay_date LIKE ''"+pWholeDate+"%'' > AND invoice_id IS null " > aResult = Payment.find_by_sql(pSql) > > how can I get the result of this? > > (when doing @aResult.inspect it returns [#"18001.25"}>])I cannot duplicate what you have as a return value in the console, so I''m just guessing ;) What is the return values class of @aResult? it looks like an array, if it is what is the class of the first element? My guess is a Payment. If you change your pSql to alias the sum(ammount) field, to say sum(ammount) as total_ammount you may be able to query it as @aResult[0].total_ammount.to_f Does that allow you to get at your value? thanks> scott > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060705/c24c8f3f/attachment.html