jordanking
Programmer
- Sep 8, 2005
- 351
Hello,
I will attempt to make this clear, forgive me if it is not.
I need to compare records in several joined tables against themselves. I have a table (residential) that tracks services provided to customers. There are two associated tables (ResidentialService and AddressLkup) that track what type of service (begin or complete) and the legal street address of the service. Once a service is started, a boolean field in the residential table is marked as true, once the service is complete a completed service record is entered into the residneital table and the bln value of the first record should be set to false, but the staff here often forget. SO I need to find all the residential records that are still "Active/true" that have another service record after the start date with a service complete type of service.
I tried to use a derived table but can not get the criteria logic to work the way I want it.
here is what I have
Basically I want to get all the residential records that are active/true and that have another residential record with the same residential.intCustomerID and AddressLkup.AddressID but a later Residential.ServiceDate and a ResidentialService.blnRemoveStatus of true
.....
I'd rather be surfing
I will attempt to make this clear, forgive me if it is not.
I need to compare records in several joined tables against themselves. I have a table (residential) that tracks services provided to customers. There are two associated tables (ResidentialService and AddressLkup) that track what type of service (begin or complete) and the legal street address of the service. Once a service is started, a boolean field in the residential table is marked as true, once the service is complete a completed service record is entered into the residneital table and the bln value of the first record should be set to false, but the staff here often forget. SO I need to find all the residential records that are still "Active/true" that have another service record after the start date with a service complete type of service.
I tried to use a derived table but can not get the criteria logic to work the way I want it.
here is what I have
Code:
SELECT Residential.intResidential, Residential.intCustomerID, Residential.blnStatus, AddressLkup.intAddressID, AddressLkup.intServiceID,
ResidentialService.blnRemoveStatus, Residential.dtServiceDate
FROM AddressLkup INNER JOIN
ResidentialService ON AddressLkup.intServiceID = ResidentialService.intServiceID RIGHT OUTER JOIN
Residential ON AddressLkup.intResidentialID = Residential.intResidential
INNER JOIN
(
SELECT Residential.intResidential, Residential.intCustomerID, Residential.blnStatus, AddressLkup.intAddressID, AddressLkup.intServiceID,
ResidentialService.blnRemoveStatus, Residential.dtServiceDate
FROM AddressLkup INNER JOIN
ResidentialService ON AddressLkup.intServiceID = ResidentialService.intServiceID RIGHT OUTER JOIN
Residential ON AddressLkup.intResidentialID = Residential.intResidential
) AS DerTable
ON Residential.intResidential = DerTable.intResidential
WHERE Residential.intCustomerID = DerTable.intCustomerID
AND AddressLkup.intAddressID = DerTable.intAddressID
Basically I want to get all the residential records that are active/true and that have another residential record with the same residential.intCustomerID and AddressLkup.AddressID but a later Residential.ServiceDate and a ResidentialService.blnRemoveStatus of true
.....
I'd rather be surfing