Can you please start from the beginning and explain the problem you're trying to solve? Show some samples of the data as well.
Why you're joining based on the hour? If that's the requirement, may be you need to store hour directly in addition to the date? Or have a computed column?
https://docs.microsoft.com/en-us/sql/relational-databases/indexes/indexes-on-computed-columns?view=sql-server-2017Thanks
>>I didn't really read the original problem, so I don't know if proposed solution is good or not. I just commented that it's better to use T-SQL to create views and not SSMS designer which can not work with complex views.
>
>Yes thanks for helping
>
>I describe issue here in short.
>
>I am using these codes provided by Sir Christian Isberner
>
>
>CREATE VIEW Test
>AS SELECT Date, DatePart(hour,Date) as Hr, reading
>FROM TABLE1 A
>WHERE Date IN
>(SELECT Min(Date) as date
>FROM TABLE1 B
>WHERE DatePart(hour,A.Date) = DatePart(hour,B.Date)
>UNION
>SELECT Min(Date) as date
>FROM TABLE2 C
>WHERE DatePart(hour,A.Date) = DatePart(hour,C.Date))
>
>
>I want to create view, the codes takes long time to display data.
>My question is: is it possible to modify above codes with JOIN clause?
>If yes then I guess the view will not take long time to display data.
>
>Regards
If it's not broken, fix it until it is.
My Blog