473,804 Members | 3,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get Most recent customer review

2 New Member
Hi All

I have a major problem with an access query and I am near the end of my tether!

I have taken over a project with a badly built access database and as resources are not available to start over I have to make do and cobble together a fix.

DB is design to record customer [Identified by Cust_ID, which is a random number generated by a different system] reviews [Identified by Review_ID, which is an Access auto number with older reviews having a lower number and more recent reviews having a higher number].

It was built as 1 table with 1 line per review. So as you can imagine you can have several reviews for the same customer over time.

What I need to do is isolate the most resent review for each customer where the day count between today and the review is less the 400.

So I have built one query to get the most Review_ID of the most recent review and the another query that gets all the relevant info for those IDs

However there seems to be no pattern to the results I get. Sometimes I get the most recent review other times I get the oldest and othertimes, when there are three reviews, I get the middle one!

Here is what I have tried:

SELECT bd1.[Client Number], Min(DateDiff("d ",bd1.[Last Updated],Date())) AS Expr1, Last(bd1.FinRev ID) AS LastOfFinRevID
FROM [Banks Databse] AS bd1
GROUP BY bd1.[Client Number]
HAVING (((Min(DateDiff ("d",[bd1].[Last Updated],Date())))<400) )
ORDER BY bd1.[Client Number], Last(bd1.FinRev ID);


Any ideas?

Thanks
Jul 3 '08 #1
3 1841
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi Anthony, and welcome to Bytes! Your logic does work - but only if an assumption is correct, which in this case it clearly isn't. The assumption is that the entries for each client will always be put into the table in date order. The last autonumber FinRevID for each client is otherwise not reflecting the last review date. It is this which is causing the apparent ordering problems for your query. The use of Last on the FinRevID is the problem here, as it is changing the grouping within the query if the entry order does not follow strict date order.

I have come to this conclusion after testing your query on sample data; your query works as expected when all entries follow in date order, but fails should a review be entered out of sequence.

To resolve this we need to break the problem down into two parts: find the most recent review date for each client, then retrieve the FinRevID that corresponds to that date (recognising that it is not necessarily the highest-value ID for that client).

Enter the query below and save it as qryLastDate:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Banks Databse].[Client Number], Max([Banks Databse].[Last Updated]) AS [Last Review]
  2. FROM [Banks Databse]
  3. GROUP BY [Banks Databse].[Client Number];
Then join qryLastDate to your [Banks Databse] table in the following query to retrieve the FinRevID value corresponding:

Expand|Select|Wrap|Line Numbers
  1. SELECT [Banks Databse].[Client Number], [Banks Databse].[Last Updated], [Banks Databse].FinRevID, DateDiff("d",[Last Updated],Date()) AS Days
  2. FROM [Banks Databse] INNER JOIN qryLastDate ON ([Banks Databse].[Last Updated] = qryLastDate.[Last Review]) AND ([Banks Databse].[Client Number] = qryLastDate.[Client Number])
  3. WHERE (((DateDiff("d",[Last Updated],Date()))<400));
Test data:
Expand|Select|Wrap|Line Numbers
  1. Client Number Last Updated FinRevID
  2. 101 ..........06/02/2007 .....1
  3. 101 ..........06/02/2008 .....2
  4. 101 ..........06/06/2008 .....3
  5. 102 ..........03/06/2006 .....4
  6. 102 ..........03/09/2007 .....5
  7. 102 ..........03/05/2008 .....6
  8. 103 ..........01/05/2006 .....7
  9. 103 ..........01/08/2007 .....8
  10. 103 ..........01/09/2007 .....9
  11. 103 ..........01/05/2008 ....10
  12. 101 ..........08/04/2008 ....11
  13. 102 ..........02/03/2008 ....12
  14. 103 ..........01/04/2008 ....13
qryLastDate:
Expand|Select|Wrap|Line Numbers
  1. Client Number Last Review
  2. 101 ..........06/06/2008
  3. 102 ..........03/05/2008
  4. 103 ..........01/05/2008
Final query result:
Expand|Select|Wrap|Line Numbers
  1. Client Number Last Updated FinRevID Days
  2. 101 ..........06/06/2008 .....3 .....27
  3. 102 ..........03/05/2008 .....6 .....61
  4. 103 ..........01/05/2008 ....10 .....63
-Stewart
Jul 3 '08 #2
AnthonyT
2 New Member
Genius Stewart

Thanks a million - that has worked perfectly.

I owe you a pint if are ever in Dublin!

Rgds
Jul 3 '08 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Glad to be of help, Anthony. Imagining that pint... Slainte!

-Stewart

..I owe you a pint if are ever in Dublin!
Jul 3 '08 #4

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

Similar topics

3
5226
by: Arvie | last post by:
I need some advice guys.. I am proposing that we get someone to do a complete audit/review of our Java application codebase, about 1000 JSPs/Servlets and 100 EJBs. If I get firms to submit proposals, what should I be asking /looking out for? I realise that running the applications through a migration tool will help but I am looking for a more through analysis of the actual codebase as well as assessment of the architecture Thanks
3
43982
by: Tim Morrison | last post by:
MSSQL2000 I have a table that contains customer transactions CustomerID Transaction TransactionDate .... I need to select the most recent record that matches a specific CustomerID.
4
3522
by: hazz | last post by:
The data access layer below returns, well, a mess as you can see on the last line of this posting. What is the best way to return customer objects via a datareader from the data layer into my view and bind them to a datagrid using BindingList. I am in need of an epiphany here. Thank you. -Greg ******************BIND ARRAY OF CUSTOMER OBJECTS TO DATAGRID ************************ private Customer c; c =...
1
4850
by: Herman Beeksma | last post by:
Hi there! I have two tables: Customer (ID, Name) Invoice (ID, Date, Customer, Amount) and want to select only the *last* invoice for each customer. It's easy to get each customer's last invoice date: SELECT Customer.Name, MAX(Invoice.Date) FROM Customer INNER JOIN Invoice ON Custimer.ID = Invoice.Customer
14
2377
by: At_sea_with_C | last post by:
Hello all, Im some way in C and i have to start on C++ to. I want your opinions on Teach yourself C++ in 21 days by Jessi Liberty. Can I go with it as my first book are are there better ones? Thanks to all. -- Email: The handle, (dot seperated), at gmail dot com.
2
1117
by: VMI | last post by:
Are there any recent threads on who the best asp.net web host is? I asked the same question about a year and a half ago and I ended up with webhost4life.com . But now I need to renew and I'm beginning to research alternatives. Are there any new, better (and cheaper) web hosts? I liked webhost4life because it was cheap and it included sql server. Thanks. VS 2005 v2.0
2
1706
by: Jeff Kish | last post by:
is there a way using sqlexpress to review the most recent set of sql commands submitted to a database? I remember something about setting up logging in sql server 2000, but don't see much about this on google or the news group for 2005. thanks Jeff Kish
7
5893
by: brewer95 | last post by:
I use a form to enter data into a table. The user then has the opportunity to recall the data in the form based on a search to review and update the info. For example, on my menu there is a combo box where the name is selected. Once the name is selected my code recalls the form with the previously entered data. The problem I have now is that when the same name is used for a new trip (same person, new trip) my form displays the data that...
1
4037
by: jpgoeth | last post by:
What I'm trying to do is select the most recent record for each customer who created an account between 2004-01-01 and 2007-01-01. I'm using MSQuery. I have this so far: SELECT OrderOrAdjust, CustomerID,OrderDate,PaymentStatus,PaymentMethod from bi_extract WHERE CustomerFirstOrderDate >=2004/01/01 AND CustomerFirstOrderDate <2007/01/01 AND OrderOrAdjust='order' AND PaymentStatus='payment approved' AND (PaymentMethod='VISA' OR...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10320
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10308
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10073
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9134
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.