Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I currently have a query that takes

Status
Not open for further replies.

boblovesyousomuch

Programmer
Dec 2, 2003
27
GB
I currently have a query that takes some information from a couple of tables and displays the various information. I then use another query to perform mathematical functions on that data. I really want the query to happen in one go put can't figure it out.

I have put the too queries below (they are big and confusing):

QryTermCodeByAgent

Code:
SELECT Stats.DO_FinalTerm AS TermCodeShort, tblTermCode.TC_Actual AS TermCodeDescript, Count(Stats.DO_FinalTerm) AS TermCodeCount, tblAgentList.A_ID, Sum(Stats.DO_Balance) AS TermCodeBalance
FROM (tblAgentList INNER JOIN Stats ON tblAgentList.A_DavoxID = Stats.DO_OperID) INNER JOIN tblTermCode ON Stats.DO_FinalTerm = tblTermCode.TC_TermCode
GROUP BY Stats.DO_FinalTerm, tblTermCode.TC_Actual, tblAgentList.A_ID, Stats.DO_DateCalled, tblAgentList.A_ID
HAVING (((tblAgentList.A_ID)=[Forms]![FrmCallSummary]![ListAgents]) AND ((Stats.DO_DateCalled) Between [Forms]![FrmCallSummary]![txtStartDate] And [Forms]![FrmCallSummary]![txtEndDate]));

QryTermCodeFullDebt
Code:
SELECT QryTermCodeByAgent.TermCodeShort, QryTermCodeByAgent.TermCodeDescript, QryTermCodeByAgent.TermCodeCount, Format([TermCodeCount]/[Connects],'Percent') AS VolumePer, QryTermCodeByAgent.TermCodeBalance, Format([TermCodeBalance]/[TotalBalance],'Percent') AS ValuePer
FROM QryTermCodeByAgent INNER JOIN QryConnects ON QryTermCodeByAgent.A_ID = QryConnects.A_ID
ORDER BY QryTermCodeByAgent.TermCodeDescript;

I want to do this so I can pull it in to VB and play around with the ORDERING etc.

Cheers for any help in advance
 
Make this change to your first query:

SELECT Stats.DO_FinalTerm AS TermCodeShort,
tblTermCode.TC_Actual AS TermCodeDescript,
Count(Stats.DO_FinalTerm) AS TermCodeCount,
tblAgentList.A_ID,
Sum(Stats.DO_Balance) AS TermCodeBalance
FROM (tblAgentList INNER JOIN Stats ON
tblAgentList.A_DavoxID = Stats.DO_OperID)
INNER JOIN tblTermCode
ON Stats.DO_FinalTerm = tblTermCode.TC_TermCode

WHERE (((tblAgentList.A_ID)=[Forms]![FrmCallSummary]![ListAgents]) AND ((Stats.DO_DateCalled) Between [Forms]![FrmCallSummary]![txtStartDate] And [Forms]![FrmCallSummary]![txtEndDate]))

GROUP BY Stats.DO_FinalTerm,
tblTermCode.TC_Actual,
tblAgentList.A_ID;

I put your conditions in the WHERE clause because the criteria are not on aggregate fields. I removed the date field because you don't include that in your final totals.

Now add in the QryConnects table linked on A_ID and you can do calculations like this:

Count(Stats.DO_FinalTerm)/Max([Connects]) AS VolumePer
Sum(Stats.DO_Balance)/Max([TotalBalance]) AS ValuePer

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top