title: Running a SQL query in rails
body: <p>I have a rails application where I have to subtract 2 time stamps and display the result on the webpage</p>
  
  <p>I  have used the following sql statement and I am getting the results.</p>
  
  <pre><code>select (julianday(resolutions.created_at)-julianday(tickets.created_at))*24 from tickets,resolutions
  </code></pre>
  
  <p>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</p>
  
  <p>Now where do I put this sql so that I can be seen in my webpage.
  I tried it in the views page with the following but nothing showed up:</p>
  
  <pre><code>&lt;% @sql = "select (julianday(resolutions.created_at)-julianday(tickets.created_at))*24 from tickets,resolutions" %&gt;
  &lt;% @t=(ActiveRecord::Base.connection.execute(@sql)) %&gt;
  </code></pre>
  
  <p>So how do I display it on my webpage?</p>
  
  <p>when I perform the above I get the output printed on the webpage as</p>
  
  <pre><code>061.1919444389641(julianday(resolutions.created_at)-julianday(tickets.created_at))*2461.1919444389641
  </code></pre>
  
  <p>only 61.1919444389641 is supposed to be printed but the query statement is also getting printed.</p>