mercredi 21 décembre 2016

Assigning multiple sql result values to the same key

I have a sql result of this form:

Id Amount1 Amount2 Amount3
1  10      10       12
2  20      13       14
3  30      15       15

I am trying to store the Id in Key and all other values in value

something like this:

{1=>{:Amount1=>"10", :Amount2=>"10", :Amount3=>"12"}, 2=>{:Amount1=>"20", :Amount2=>"13", :Amount3=>"14"}}

This is what I currently have so far:

hashn = Hash.new

  sqlresult.each { |x|  
    hashn[x['PPS_Id']] = x['Gift_Card_Amount1']
    hashn[x['PPS_Id']] = x['Gift_Card_Amount2']
    hashn[x['PPS_Id']] = x['Gift_Card_Amount3']
}

I believe this overrides the previous value can you please help.

Aucun commentaire:

Enregistrer un commentaire