title: How to convert the query to HQL?
body: <p>I have this query in SQL Server that consumes two parameters <code>startDate</code> and <code>endDate</code>.</p>
  
  <p>Could you help me to convert it to HQL in order to make it database independent?</p>
  
  <pre><code>SELECT LeaseTable.CarMake, AVG(LeaseTable.LeaseHours)
  FROM
  (SELECT lease.carmake, 
      DATEDIFF(HH, case when lease.startDate &lt;@startdate then @startdate else lease.startDate end, dateadd(DD, 1 ,case when lease.endDate &gt; @endDate then @endDate else lease.endDate end)) as LeaseHours
      FROM lease
  where 
      lease.startDate &lt;= @endDate AND lease.endDate &gt;= @startdate) as LeaseTable
  GROUP BY LeaseTable.carMake 
  </code></pre>