I need to perform these SQL below, but I couldn't get the result.
newid=Header.find_by_sql(
"SELECT coalesce(max(transaction_id),0)+1 AS id
FROM transaction_headers
WHERE transaction_year = #{Time.now.year} AND
transaction_type='#{fields[:transaction_type]}'"
)
But I can't seem to get the result to newid. The only value I got was [#<Header>] Anyone can help me to create the correct statement for Ruby?
EDIT: Table fields
----------------------------------------------------------------------------------- | transaction_type | transaction_year | transaction_id | customer_id | uid | date | -----------------------------------------------------------------------------------
Thank you.