Running a SQL query in rails

Posted by Bharat on Stack Overflow See other posts from Stack Overflow or by Bharat
Published on 2010-04-10T16:35:59Z Indexed on 2010/04/10 16:43 UTC
Read the original article Hit count: 373

Filed under:
|

Hello

I have a rails application where I have to subtract 2 time stamps and display the result on the webpage

I have used the following sql statement and I am getting the results.

select (julianday(resolutions.created_at)-julianday(tickets.created_at))*24 from tickets,resolutions

the value of tickets.created_at is 2010-04-05 18:59:02 which is a time stamp and value of resolutions.created_at is 2010-04-08 08:10:33

Now where do I put this sql so that I can be seen in my webpage. I tired it in the views page with the following but nothing showed up:

<% @sql = "select (julianday(resolutions.created_at)-julianday(tickets.created_at))*24 from tickets,resolutions" %>
<% @t=(ActiveRecord::Base.connection.execute(@sql)) %>

So how do I display it on my webpage?

when I perform the above I get the output printed on the webpage as

061.1919444389641(julianday(resolutions.created_at)-julianday(tickets.created_at))*2461.1919444389641

only 61.1919444389641 is supposed to be printed but the query statement is also getting printed.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about sql