473,387 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help with Joins/Query

Hello all!
I've searched the forum for I am sure my answer lies within somewhere, but I was unable to apply what I found to solve my question.

I have two tables:

tProspects
-id (autonumber)
-CLECNumber
-CompanyName

tContactslog
-id (autonumber)
-CLECNumber
-callDate
-CallResult.

I cannot figure out a join issue. . The tProspects is a complete customer list. The tcontactslog has each type of contact made to the customer with the CLECListNumber as the id in common. When a customer is contacted, contact log record is created. There are multiple contact records for a Customer though not all Customers have been contacted. I need to do two things:

1) return a table (query result) which shows me all of the prospects in tprospects that do not have “not interested” as a call result in tContacts
2) after filtering out the ones that have "not interested" in CallResult, return a result that which includes the most recent (ONLY) callresult and Calldate from tcontacts, if any there is anything.

I am using MS Access 2007.

Thanks.
Jul 23 '07 #1
6 1328
JKing
1,206 Expert 1GB
Hi, what do you consider as the most recent? Do you want to return any calls within the last 5 days? last day? Or just the single record with the most recent date?

To filter your results your query would be something like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM tProspects INNER JOIN tContactslog ON tContactslog.CLECNumber = tProspects.CLECNumber
  3. WHERE CallResult <> 'not interested'
  4.  
Jul 23 '07 #2
kepston
97 Expert
Hello all!
I've searched the forum for I am sure my answer lies within somewhere, but I was unable to apply what I found to solve my question.

I have two tables:

tProspects
-id (autonumber)
-CLECNumber
-CompanyName

tContactslog
-id (autonumber)
-CLECNumber
-callDate
-CallResult.

I cannot figure out a join issue. . The tProspects is a complete customer list. The tcontactslog has each type of contact made to the customer with the CLECListNumber as the id in common. When a customer is contacted, contact log record is created. There are multiple contact records for a Customer though not all Customers have been contacted. I need to do two things:

1) return a table (query result) which shows me all of the prospects in tprospects that do not have “not interested” as a call result in tContacts
2) after filtering out the ones that have "not interested" in CallResult, return a result that which includes the most recent (ONLY) callresult and Calldate from tcontacts, if any there is anything.

I am using MS Access 2007.

Thanks.
If I am understanding you correctly, try
Expand|Select|Wrap|Line Numbers
  1. SELECT tProspects.CLECNumber, CompanyName, calldate,callresult
  2. FROM tProspects INNER JOIN tContactslog ON tProspects.CLECNumber = tContactslog.CLECNumber
  3. WHERE callresult <>"not interested” AND calldate>=[Date From];
The [Date From] will prompt for a user input and then show all records from that date where an interest was shown.

Welcome to The Scripts.
Jul 23 '07 #3
Great!

I'm halfway home!

This worked to exclude those customers that have expressed "not interested from my list. (I added the "Ordered Service" as an additional criterion)

SELECT *
FROM tCLECProspects AS t1
WHERE (((Exists (select * from tContactLog where (callresult= 'Not Interested' AND tContactLog.CLECListNumber= t1.CLECListNumber) or callresult= 'Ordered Service' AND tContactLog.CLECListNumber= t1.CLECListNumber ))=False));

Now, I am trying to return the contents of the "CallResult" record, if exists of course as not all customers will have been contacted on any day. But, I need only the latest ONLY CallResultfield/record (from tContactLog) for each customer that has been previously contacted and has not been finalized as "not interested" or "ordered service" (e.g. still an active prospect) ).

These results populate a continuous form so our folks can see a list of prospects to contact and see the result LAST contact made with that contact.
Jul 23 '07 #4
kepston
97 Expert
Great!

I'm halfway home!

This worked to exclude those customers that have expressed "not interested from my list. (I added the "Ordered Service" as an additional criterion)

SELECT *
FROM tCLECProspects AS t1
WHERE (((Exists (select * from tContactLog where (callresult= 'Not Interested' AND tContactLog.CLECListNumber= t1.CLECListNumber) or callresult= 'Ordered Service' AND tContactLog.CLECListNumber= t1.CLECListNumber ))=False));

Now, I am trying to return the contents of the "CallResult" record, if exists of course as not all customers will have been contacted on any day. But, I need only the latest ONLY CallResultfield/record (from tContactLog) for each customer that has been previously contacted and has not been finalized as "not interested" or "ordered service" (e.g. still an active prospect) ).

These results populate a continuous form so our folks can see a list of prospects to contact and see the result LAST contact made with that contact.
You will need to use the Max() aggregate function on your date field, in the SELECT clause.
You may have to split into two queries.
Jul 23 '07 #5
You will need to use the Max() aggregate function on your date field, in the SELECT clause.
You may have to split into two queries.

I was thinking that. I tried Max() or Top 1 (using a sort on date) a couple of different ways, but ended up with the latest for the entire table and not the last/latest for each distinct number found (e.g. last of multiple contacts to each customer in table)
Jul 23 '07 #6
kepston
97 Expert
I was thinking that. I tried Max() or Top 1 (using a sort on date) a couple of different ways, but ended up with the latest for the entire table and not the last/latest for each distinct number found (e.g. last of multiple contacts to each customer in table)
You will have to select specific fields e.g. customer and Max(calldate) and GROUP BY customer.
That should get you closer.
Jul 23 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
2
by: Preston Landers | last post by:
Hello all. I am trying to write a query that "just" switches some data around so it is shown in a slightly different format. I am already able to do what I want in Oracle 8i, but I am having...
4
by: jbm05 | last post by:
Hi, I'm curious about the computational complexity of a query I have. The query contains multiple nested self left joins, starting with a simple select, then doing a self left join with the...
1
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
7
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
1
by: Lumpierbritches | last post by:
I'm trying to pull all the parents of a particular animal and I have my SQL statement that says not supported and when I attempt to run the Query, I get The SQL statement couldn't be executed...
1
by: Phil W | last post by:
Hello, I have set up my database in access using many to many relationships (it's the good ol' books and authors one again). I've actually extended it to include other people who contribute in...
5
by: khan | last post by:
i have 2 queries totaldues and totalPayments totaldues has 2 fileds(custID (Group By) amountDue(sum of all invoices dues) and totalPayments consist of CustID(Group By) and Amount_Paid(sum of all...
2
by: gkellymail | last post by:
the following query works fine: select link.idx, link.x_table, link.x_id_a, link.x_id_z, a.strandid, b.strandid from link_detail, link, strand A, strand B where link_detail.x_table =...
36
by: TC | last post by:
I've used Access for many years. Several times, I've encountered a bug which I refer to as the "Vanishing Joins" bug. When it happens, joins vanish randomly from queries. More specifically, all...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.