473,403 Members | 2,323 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,403 software developers and data experts.

Sql query: If a date exists for the record add the last one in.

374 256MB
I have a system where records are created, costs added to the record and also E-mails that are sent using access are logged and attached to the record.

These emails have a date+time sent field attached to them so I can basically look at a record and see any communication history.

At present I produce a query which contains the following information:

Expand|Select|Wrap|Line Numbers
  1. NCC_ID    DteReport    DteOccur    DeptRaisedBy    DeptResp    NCStatus    SumOfCostFig
  2. 472    03/06/2010    20/05/2010    Service Facility - Heavy Machining    Service Facility - Heavy Machining    Awaiting Closure    £700.00
  3. 521    05/07/2010    02/07/2010    Service Facility - Blading    Service Facility - Blading    Awaiting Closure    £1,260.00
  4. 522    05/07/2010    25/06/2010    Business Excellence    HS&E    Pending Acceptance    £125.00
  5. 524    06/07/2010    09/06/2010    Finance & Commercial    HS&E    Awaiting Closure    £400.00
  6. 525    06/07/2010    05/06/2010    Finance & Commercial    Field Service    Action Being Taken    £80.00
  7. 536    10/07/2010    08/06/2010    Service Facility - Generator Assembly    Service Facility - Generator Assembly    Initial Notification    £40.00
However, I now want to add the following:

If an E-mail has been sent, I want the last date e.g. The newest E mail date to be attached.

My sql for the above is:

Expand|Select|Wrap|Line Numbers
  1. SELECT tbllog.NCC_ID, tbllog.DteReport, tbllog.DteOccur, tbldept_1.Department AS DeptRaisedBy, tbldept.Department AS DeptResp, tblstatus.NCStatus, Sum(tblCosts.CostFig) AS SumOfCostFig
  2. FROM (tblstatus INNER JOIN ((tbllog INNER JOIN tbldept AS tbldept_1 ON tbllog.DeptRaisedBy = tbldept_1.DeptID) INNER JOIN tbldept ON tbllog.DeptResp = tbldept.DeptID) ON tblstatus.NCStatusID = tbllog.NCStatus) INNER JOIN tblCosts ON tbllog.NCC_ID = tblCosts.NCC_ID
  3. GROUP BY tbllog.NCC_ID, tbllog.DteReport, tbllog.DteOccur, tbldept_1.Department, tbldept.Department, tblstatus.NCStatus;
Quite a long mess due to using the in built wizard. However when I add in the E-mail date field I am only being shown two records, the two records that have had emails sent in the past.

I want to see all records, but only attach the date if there has been an email sent, also the last of these.

Hard to explain and likely confusing if any more information is required don't hesitate to ask.

Thanks,

Chris

PS the set up of my query:

Jul 15 '10 #1

✓ answered by nico5038

You'll need to double click the connection line between the existing table and the email table. Then select the option that the existing table is always present and that the email table is optional. An arrow will occur directing to the email table when all is OK.

This is called a LEFT or RIGHT JOIN....

Nic;o)

3 1920
mseo
181 100+
@munkee
hi,
you can use something like: Max(date) you posted your query and mentioned few details about what your problem , please, try to restate the problem, to let us understand your question clearly
hope this helps
Jul 15 '10 #2
munkee
374 256MB
Thanks for the reply.

The problem is as soon as I add in the date field from the tblEmail to join it to the query. I only get results returned for records that have an email in the tblEmail.

I want to show both those with dates and those without, if there is a date I want to show the last date, or max like you stated. If there isnt I want it to be blank.
Jul 15 '10 #3
nico5038
3,080 Expert 2GB
You'll need to double click the connection line between the existing table and the email table. Then select the option that the existing table is always present and that the email table is optional. An arrow will occur directing to the email table when all is OK.

This is called a LEFT or RIGHT JOIN....

Nic;o)
Jul 15 '10 #4

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

Similar topics

7
by: JP SIngh | last post by:
Hi All We have two tables EmpProfile and holidaysrequest tables. EmpProfile has fields EmpNo Firstname Lastname etc HolidayRequests has fields
1
by: Lukelrc | last post by:
Hi. I have a table (websitehits) which holds statistics about websites. This table has a date field (datecounted). What I need is to create a query which returns a list of dates between two date...
2
by: Paul# | last post by:
how do i query for a record between two dates using Access 2000? right now Im doing this: SELECT * FROM tblDateTotal WHERE .<>0 And . Between 1/1/1901 And 10/10/2050;
3
by: Melissa | last post by:
I have this table: TblProjectYear ProjectYearID ProjectYearStartDate ProjectYearEndDate The Project Year will always span across December 31; for example 9/1/04 to 6/30/05. How do I build a...
12
by: Bookreader | last post by:
I tried Googling this but I get a whole lot of replies about running the SQL statement in VB via ADO. All I want to do is run an existing ACCESS 2000 query from VB with no information returned...
1
by: Kevin.S.Campbell | last post by:
Greetings, I'm trying to run a sql query on a continous form. I have the query working correctly the way I want it. I want this query to be displayed on the form in the text box on the load...
2
by: kkleung89 | last post by:
Basically, here's what's happening with the program. I have a table of Customers and a table of Pets, with the latter containing a field linking it to its customer of ownership. I have a form...
2
by: zdk | last post by:
I have table name "actionlog",and one field in there is "date_time" date_time (Type:datetime) example value : 11/1/2006 11:05:07 if I'd like to query date between 24/07/2006 to 26/07/2006(I...
19
by: phill86 | last post by:
Hi I am re-posting this thread because it has become very confusing and I have got some way to solving the problem so it is a slightly different question from the initial thread. here is the...
1
by: karuppiah | last post by:
Hi All, i need query,how to select last 3 month ,last 3wek,last 3 days , this last 3 month and 3 week should be friday, using sysdate from dual table, there is no exsting table, pls any one help...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.