You tell us what does not work, and want us to try to understand what your code tries to do. That's not a very helpful...! Instead you should tell us what exactly you want, and add the details necessary.
And you should also provide some sample data, so that we can test what we suggest for you. See my signature for help on providing sample data.
>Sir, I am using these codes with sqlserver 2008.
>
>I am trying to get data from two tables like this
>
>
>SELECT Date, DatePart(hour,Date) as Hr, reading
>FROM TABLE1 A
>WHERE Date =
>
>(SELECT Min(Date) as date
> FROM TABLE1 B
> WHERE DatePart(hour,A.Date)= DatePart(hour,B.Date)
>
> union all
>
> SELECT Min(Date)as date
> FROM TABLE2 C
> WHERE DatePart(hour,A.Date)= DatePart(hour,C.Date))
>
>
>but I am facing this error message
>
>
>Msg 512, Level 16, State 1, Line 1
>Subquery returned more than 1 value. This is not permitted when the subquery follows or when the subquery is used as an expression.
>
>How to overcome this?
>
>
>But this query work fine
>
>
>SELECT Date, DatePart(hour,Date) as Hr, reading
>FROM TABLE1 A
>WHERE Date =
>
>(SELECT Min(Date) as date
> FROM TABLE1 B
> WHERE DatePart(hour,A.Date)= DatePart(hour,B.Date) )
>
>
>
>
>
>
>Please