![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi: A subquery has me stumped. *Suggestions appreciated... Simplified sql is Select Field1, Field2, (Select Max(FieldA) from tblEvent where tblEvent.Field1 = Field1) as LastEvent, (Select FieldB from tblEvent where tblEvent.Field1 = Field1 and tblEvent.FieldA = LastEvent) from tblComponent where Field2 = "AAA" Access is objecting to the tblEvent.FieldA = LastEvent in the second subquery (specifically the "LastEvent" part) how do I delimit the "LastEvent" criteria in the second subquery to let Access know it should use the result of the first subquery as the criteria? In case I oversimplified, and you need to look at the actual SQL statement, here it is: SELECT dbo_tblComponent.FacilityID, dbo_tblComponent.TagNumber, IIf([CompFrequency]="Exempt","Exempt","Not Exempt") AS CompStatus, (select max(EventDate) from dbo_tblEvents where ((dbo_tblEvents.FacilityID = facilityID and dbo_tblEvents.EventTagNumber = tagnumber) and (dbo_tblEvents.EventType = "Startup" or dbo_tblEvents.EventType = "In Service" or dbo_tblEvents.EventType = "Shutdown" or "Out of Service" or dbo_tblEvents.EventType = "TOS" ))) AS LastStatusDate, (select EventType from dbo_tblEvents where dbo_tblEvents.facilityID = FacilityID and dbo_tblEvents.EventTagNumber = TagNumber and dbo_tblEvents.EventDate = (LastServiceDate)) AS compActive FROM dbo_tblComponent WHERE (((dbo_tblComponent.FacilityID)=1)) ORDER BY dbo_tblComponent.FacilityID, dbo_tblComponent.TagNumber; Thanks |
#3
| |||
| |||
|
|
A subquery has me stumped. Suggestions appreciated... Simplified sql is Select Field1, Field2, (Select Max(FieldA) from tblEvent where tblEvent.Field1 = Field1) as LastEvent, (Select FieldB from tblEvent where tblEvent.Field1 = Field1 and tblEvent.FieldA = LastEvent) from tblComponent where Field2 = "AAA" Access is objecting to the tblEvent.FieldA = LastEvent in the second subquery (specifically the "LastEvent" part) |
#4
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |