Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get data from 2 tables
Message
From
09/02/2019 06:36:47
 
 
To
08/02/2019 19:07:16
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2008 R2
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01666006
Message ID:
01666198
Views:
51
>>>Sir you used your following codes
>>>
>>>
>>>SELECT Date, DatePart(hour,Date) as Hr, reading
>>>FROM bin1_empty A
>>>WHERE EXISTS( 
>>>(SELECT Min(Date) as date_B
>>>FROM bin1_empty B
>>>WHERE DatePart(hour,A.Date) = DatePart(hour,B.Date) 
>>>HAVING B.Date_B = A.Date)
>>>OR EXISTS(
>>>SELECT Min(Date) as date_C
>>>FROM bin1 C
>>>WHERE DatePart(hour,A.Date) = DatePart(hour,C.Date)
>>>HAVING C.Date_C = A.Date)
>>>
>>>
>>>but it has error shown in image.
>>
>>
>>I think there was one ) too much:
>>
>>
>>SELECT Date, DatePart(hour,Date) as Hr, reading
>>FROM bin1_empty A
>>WHERE EXISTS( 
>>SELECT Min(Date) as date_B
>>FROM bin1_empty B
>>WHERE DatePart(hour,A.Date) = DatePart(hour,B.Date) 
>>HAVING B.Date_B = A.Date)
>>OR EXISTS(
>>SELECT Min(Date) as date_C
>>FROM bin1 C
>>WHERE DatePart(hour,A.Date) = DatePart(hour,C.Date)
>>HAVING C.Date_C = A.Date)
>>
>
>
>Sir it has still error like shown in image.

Indeed, in the having clause you must refer to the Expression and not to the field name. Therefore C.Date_C does not exist. My fault: It should have been Having MIN(date):

Also I would prefix all field names with the Alias to make sure it is understandable.
SELECT A.Date, DatePart(hour,A.Date) as Hr, A.Reading
FROM bin1_empty A
WHERE EXISTS( 
SELECT Min(B.Date) as date_B
FROM bin1_empty B
WHERE DatePart(hour,A.Date) = DatePart(hour,B.Date) 
HAVING Min(B.Date) = A.Date)
OR EXISTS(
SELECT Min(C.Date) as date_C
FROM bin1 C
WHERE DatePart(hour,A.Date) = DatePart(hour,C.Date)
HAVING Min(C.Date) = A.Date)
Christian Isberner
Software Consultant
Previous
Reply
Map
View

Click here to load this message in the networking platform