;with cteAllData as (select [Date], datepart(hour, [Date]) as [Hour], Reading from table1 UNION ALL select [Date], datepart(hour, [Date]) as [Hour], Reading from table2), cteNumbered as (select *, row_number() over (partition by [Date] Order by [Hour]) as Rn from cteAllData) select [Date], [Hour], Reading from cteNumbered where Rn = 1----------------------
create view HourlyReadings as with cteAllData as (select [Date], datepart(hour, [Date]) as [Hour], Reading from table1 UNION ALL select [Date], datepart(hour, [Date]) as [Hour], Reading from table2), cteNumbered as (select *, row_number() over (partition by [Date] Order by [Hour]) as Rn from cteAllData) select [Date], [Hour], Reading from cteNumbered where Rn = 1I didn't test, wrote from the top of my head, hopefully it'll work.
>CREATE CURSOR table1(date t,reading n(4)) >INSERT INTO table1 values({^2019-02-09 11:19:21 AM}, 1100) >INSERT INTO table1 values({^2019-02-09 11:25:38 AM}, 1105) >INSERT INTO table1 values({^2019-02-09 12:42:07 PM}, 1110) > > >CREATE CURSOR table2(date t,reading n(4)) >INSERT INTO table2 values({^2019-02-08 01:46:27 AM}, 2480) >INSERT INTO table2 values({^2019-02-08 01:55:58 AM}, 2485) >INSERT INTO table2 values({^2019-02-08 02:12:33 AM}, 2490) >INSERT INTO table2 values({^2019-02-09 03:43:29 AM}, 2495) >INSERT INTO table2 values({^2019-02-09 03:50:18 AM}, 2500) >INSERT INTO table2 values({^2019-02-09 04:12:21 AM}, 2505) >INSERT INTO table2 values({^2019-02-09 04:25:38 AM}, 2510) >INSERT INTO table2 values({^2019-02-09 05:37:29 AM}, 2515) > > >>