Get value from array

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

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…?

On 7/5/06, ben [email protected] wrote:

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 :wink:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs