O
obfruscated
i've had the unpleasant honor of having to add functionality to a
database that already is a kludge, what would normally be easy on a db
that was designed properly is turning into my month long nightmare. I
have experience with oracle/sql but access is a new beast for me. this
first query i wonder if theres a way to speed it up, it currently takes
about 5 minutes but it works just fine.
its rather lengthy
SELECT DISTINCT Applicants.CompanyName, Applicants.Address1,
Applicants.Address2, Applicants.City, Applicants.State, Applicants.Zip,
[Applicants-Contacts].Ins_Name, [Applicants-Contacts].Ins_address1,
[Applicants-Contacts].Ins_address2, [Applicants-Contacts].Ins_city,
[Applicants-Contacts].Ins_state, [Applicants-Contacts].Ins_zip,
Coverages.LimitN, Coverages.LimitW,
GetItemList("Products","Contracts",Contracts.ContractID) AS Items
FROM ((((Applicants INNER JOIN [Applicants-Contacts] ON
Applicants.AppID=[Applicants-Contacts].AppID) INNER JOIN
ApplicationFees ON Applicants.AppID=ApplicationFees.AppID) INNER JOIN
Contracts ON (Applicants.AppID=Contracts.AppID) AND
(ApplicationFees.ContractID=Contracts.ContractID)) INNER JOIN Coverages
ON Applicants.AppID=Coverages.AppID) INNER JOIN Products ON
Contracts.ContractID=Products.ContractID
WHERE (((Contracts.ContractStatus)="Fully Executed") And
((ApplicationFees.Fee)=300) And
(contracts.term=forms!Renewal!comboStartDate));
what this does is returns all the information regarding applicants and
how much they've paid for their term. if i take DISTINCT out it runs
much faster BUT it returns multiples of the same applicants who have
more than 1 item. so if applicant 1 has 5 items, all of applicant 1's
info is returned 5 times, it doesn't make for a pretty mailmerge
document
the second query that's giving me absolute fits is a variation on the
above query, the applicants have the choice of paying 1 time for 300 or
3 times for 125 each. what i'm trying to do is use a sub query but i'm
finding out that access doesn't really like it the way i want to do
it.
SELECT DISTINCT Applicants.CompanyName AS Company, Applicants.Address1,
Applicants.Address2, Applicants.City, Applicants.State, Applicants.Zip,
[Applicants-Contacts].Ins_Name, [Applicants-Contacts].Ins_address1,
[Applicants-Contacts].Ins_address2, [Applicants-Contacts].Ins_city,
[Applicants-Contacts].Ins_state, [Applicants-Contacts].Ins_zip,
Coverages.LimitN, Coverages.LimitW,
GetItemList("Products","Contracts",Contracts.ContractID) AS Items
FROM ((((Applicants INNER JOIN [Applicants-Contacts] ON
Applicants.AppID=[Applicants-Contacts].AppID) INNER JOIN
ApplicationFees ON Applicants.AppID=ApplicationFees.AppID) INNER JOIN
Contracts ON (ApplicationFees.ContractID=Contracts.ContractID) AND
(Applicants.AppID=Contracts.AppID)) INNER JOIN Coverages ON
Applicants.AppID=Coverages.AppID) INNER JOIN Products ON
Contracts.ContractID=Products.ContractID
WHERE EXISTS (select applicationfees.contractid,
sum(applicationfees.fee) as SumOfFee
from applicationfees
where (applicationfees.contractid is not null)
and (lcase(contracts.contractstatus = "fully executed"))
group by applicationfees.contractid
having sum(applicationfees.fee) =375) and
(contracts.expirationdate = [forms]![renewal]![comboEndDate]
);
what i need is for the inner query to select all who paid 375 and then
the outter query to grab all the other nastiness where
contracts.contracid in (subquery)
any ideas or do i need to be more specific in what i'm asking for?
database that already is a kludge, what would normally be easy on a db
that was designed properly is turning into my month long nightmare. I
have experience with oracle/sql but access is a new beast for me. this
first query i wonder if theres a way to speed it up, it currently takes
about 5 minutes but it works just fine.
its rather lengthy
SELECT DISTINCT Applicants.CompanyName, Applicants.Address1,
Applicants.Address2, Applicants.City, Applicants.State, Applicants.Zip,
[Applicants-Contacts].Ins_Name, [Applicants-Contacts].Ins_address1,
[Applicants-Contacts].Ins_address2, [Applicants-Contacts].Ins_city,
[Applicants-Contacts].Ins_state, [Applicants-Contacts].Ins_zip,
Coverages.LimitN, Coverages.LimitW,
GetItemList("Products","Contracts",Contracts.ContractID) AS Items
FROM ((((Applicants INNER JOIN [Applicants-Contacts] ON
Applicants.AppID=[Applicants-Contacts].AppID) INNER JOIN
ApplicationFees ON Applicants.AppID=ApplicationFees.AppID) INNER JOIN
Contracts ON (Applicants.AppID=Contracts.AppID) AND
(ApplicationFees.ContractID=Contracts.ContractID)) INNER JOIN Coverages
ON Applicants.AppID=Coverages.AppID) INNER JOIN Products ON
Contracts.ContractID=Products.ContractID
WHERE (((Contracts.ContractStatus)="Fully Executed") And
((ApplicationFees.Fee)=300) And
(contracts.term=forms!Renewal!comboStartDate));
what this does is returns all the information regarding applicants and
how much they've paid for their term. if i take DISTINCT out it runs
much faster BUT it returns multiples of the same applicants who have
more than 1 item. so if applicant 1 has 5 items, all of applicant 1's
info is returned 5 times, it doesn't make for a pretty mailmerge
document
the second query that's giving me absolute fits is a variation on the
above query, the applicants have the choice of paying 1 time for 300 or
3 times for 125 each. what i'm trying to do is use a sub query but i'm
finding out that access doesn't really like it the way i want to do
it.
SELECT DISTINCT Applicants.CompanyName AS Company, Applicants.Address1,
Applicants.Address2, Applicants.City, Applicants.State, Applicants.Zip,
[Applicants-Contacts].Ins_Name, [Applicants-Contacts].Ins_address1,
[Applicants-Contacts].Ins_address2, [Applicants-Contacts].Ins_city,
[Applicants-Contacts].Ins_state, [Applicants-Contacts].Ins_zip,
Coverages.LimitN, Coverages.LimitW,
GetItemList("Products","Contracts",Contracts.ContractID) AS Items
FROM ((((Applicants INNER JOIN [Applicants-Contacts] ON
Applicants.AppID=[Applicants-Contacts].AppID) INNER JOIN
ApplicationFees ON Applicants.AppID=ApplicationFees.AppID) INNER JOIN
Contracts ON (ApplicationFees.ContractID=Contracts.ContractID) AND
(Applicants.AppID=Contracts.AppID)) INNER JOIN Coverages ON
Applicants.AppID=Coverages.AppID) INNER JOIN Products ON
Contracts.ContractID=Products.ContractID
WHERE EXISTS (select applicationfees.contractid,
sum(applicationfees.fee) as SumOfFee
from applicationfees
where (applicationfees.contractid is not null)
and (lcase(contracts.contractstatus = "fully executed"))
group by applicationfees.contractid
having sum(applicationfees.fee) =375) and
(contracts.expirationdate = [forms]![renewal]![comboEndDate]
);
what i need is for the inner query to select all who paid 375 and then
the outter query to grab all the other nastiness where
contracts.contracid in (subquery)
any ideas or do i need to be more specific in what i'm asking for?