select top 1 for each hour (hour wise) using SQL SERVER query
<p>I need one query to get some list of records hour wise between two date-time and I want to get last record from each hour, if data does not exist in the data-table then I need to show hour wise  but <code>importwh</code> default value should be zero.</p>

<p>result should be like bellow  </p>

<pre><code>SNO Startdate               enddate                 ImportWH  
1   2016-12-05 00:00:00.000 2016-12-05 00:59:59.000   0  
2   2016-12-05 01:00:00.000 2016-12-05 01:59:59.000   0  
3   2016-12-05 02:00:00.000 2016-12-05 02:59:59.000   0  
4   2016-12-05 03:00:00.000 2016-12-05 03:59:59.000   0  
5   2016-12-05 04:00:00.000 2016-12-05 04:59:59.000   0  
6   2016-12-05 05:00:00.000 2016-12-05 05:59:59.000   0  
7   2016-12-05 06:00:00.000 2016-12-05 06:59:59.000   0  
8   2016-12-05 07:00:00.000 2016-12-05 07:59:59.000   0  
9   2016-12-05 08:00:00.000 2016-12-05 08:59:59.000   0  
10  2016-12-05 09:00:00.000 2016-12-05 09:59:59.000   0  
11  2016-12-05 10:00:00.000 2016-12-05 10:59:59.000   0  
12  2016-12-05 11:00:00.000 2016-12-05 11:59:59.000   0  
13  2016-12-05 12:00:00.000 2016-12-05 12:59:59.000   0  
14  2016-12-05 13:00:00.000 2016-12-05 13:59:59.000   0  
15  2016-12-05 14:00:00.000 2016-12-05 14:59:59.000   0  
16  2016-12-05 15:00:00.000 2016-12-05 15:59:59.000   0  
17  2016-12-05 16:00:00.000 2016-12-05 16:59:59.000   0  
18  2016-12-05 17:00:00.000 2016-12-05 17:59:59.000   0  
19  2016-12-05 18:00:00.000 2016-12-05 18:59:59.000   0  
20  2016-12-05 19:00:00.000 2016-12-05 19:59:59.000   0  
21  2016-12-05 20:00:00.000 2016-12-05 20:59:59.000   0  
22  2016-12-05 21:00:00.000 2016-12-05 21:59:59.000   0  
23  2016-12-05 22:00:00.000 2016-12-05 22:59:59.000   0  
24  2016-12-05 23:00:00.000 2016-12-07 23:59:59.000   0  
</code></pre>

<p>for example data</p>

<pre><code>SNO Startdate               enddate                 ImportWH  
1   2016-12-05 00:00:00.000 2016-12-05 00:59:59.000   0.1  
2   2016-12-05 00:00:00.000 2016-12-05 00:59:59.000   0.1  
3   2016-12-05 00:00:00.000 2016-12-05 00:59:59.000   2  
4   2016-12-05 01:00:00.000 2016-12-05 01:59:59.000   1  
5   2016-12-05 01:00:00.000 2016-12-05 01:59:59.000   2   
</code></pre>

<p>should be result like bellow
      SNO   Startdate               enddate              ImportWH  </p>

<pre><code>1   2016-12-05 00:00:00.000 2016-12-05 00:59:59.000   2 
1   2016-12-05 01:00:00.000 2016-12-05 01:59:59.000   2 
</code></pre>