473,387 Members | 1,942 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.

Dmax criteria in Query

18
I have the following in Db:-

tbl_Est - Num_ClaimNo
- Date_Date
- Num_Estimate

I need this query to link to data in another table - tbl_Bord05, in which there is also a field called Num_Estimate and Num_ClaimNo.

I need to query tbl_Est to return the highest Date_Date for each Num_ClaimNo appearing in tbl_Est, where Num_ClaimNo also appears in tbl_Bord05.

I have had it working insomuch as the query (which I have now deleted) was returning the Num_ClaimNo, Datae_Date and Num_Estimate but only for one record - the one with the highest date!

Any assistance would be greatly appreciated. My limited success so far has come using the DMax function in the query criteria.

Happy to get any SQL that will do the trick.

Cheers in advance.
VJ
Jun 10 '08 #1
6 4823
puppydogbuddy
1,923 Expert 1GB
Try this and see if it helps:

Expand|Select|Wrap|Line Numbers
  1. Select tbl_Est.[Num_ClaimNo], tbl_Est.[Date_Date], tbl_Est.[Num_Estimate], Max("tbl_Est.[Date_Date]") as MaxClaimDate, tbl_Bord05.[Num_ClaimNo]
  2. From tbl_Est, tbl_Bord05
  3. Where tbl_Est.[Num_ClaimNo] = tbl_Bord05.[Num_ClaimNo] And tbl_Est.[Date_Date] =  Max("tbl_Est.[Date_Date]") 
  4. Group By tbl_Est.[Num_ClaimNo] 
  5. Order By tbl_Est.[Num_ClaimNo]
Jun 10 '08 #2
puppydogbuddy
1,923 Expert 1GB
If the above code does not get it try it this way:

Expand|Select|Wrap|Line Numbers
  1. Select tbl_Est.[Num_ClaimNo], tbl_Est.[Date_Date], tbl_Est.[Num_Estimate], Max("tbl_Est.[Date_Date]") as MaxClaimDate, tbl_Bord05.[Num_ClaimNo]
  2. From tbl_Est, tbl_Bord05
  3. Where tbl_Est.[Num_ClaimNo] = tbl_Bord05.[Num_ClaimNo] 
  4. Group By tbl_Est.[Num_ClaimNo] 
  5. Having tbl_Est.[Date_Date] =  Max("tbl_Est.[Date_Date]")
  6. Order By tbl_Est.[Num_ClaimNo]
Jun 11 '08 #3
vljones
18
Try this and see if it helps:

Expand|Select|Wrap|Line Numbers
  1. Select tbl_Est.[Num_ClaimNo], tbl_Est.[Date_Date], tbl_Est.[Num_Estimate], Max("tbl_Est.[Date_Date]") as MaxClaimDate, tbl_Bord05.[Num_ClaimNo]
  2. From tbl_Est, tbl_Bord05
  3. Where tbl_Est.[Num_ClaimNo] = tbl_Bord05.[Num_ClaimNo] And tbl_Est.[Date_Date] =  Max("tbl_Est.[Date_Date]") 
  4. Group By tbl_Est.[Num_ClaimNo] 
  5. Order By tbl_Est.[Num_ClaimNo]


Unfortunately that did not work. Cannot have aggregate function in WHERE clause <clause>. (Error 3096) is displayed.

To make it a little clearer, tbl_Bord05 is a query made table which populates some fields with a zero value. These fields are the are then to be updated with the query I am trying to build here.

tbl_Estimate stores multiple records per Num_ClaimNo.

I need to retrieve from tbl_Est, the data in fields Num_ClaimNo, Date_Date and Num_Estimate, but only where Num_ClaimNo in tbl_Est also exists in tbl_Bord05. If this is true then Date_date from tbl_Estimate needs to be the highest date for each Num_ClaimNo appearing in tbl_Estimate, as well as the corresponding Num_estimate value.

Once I have the select working properly I will then be updating these fields in tbl_Bord05 from the data retrieved from this query.

Sorry SQL is not my strongest point, am getting better but it still confuses me sometimes.

Thanks so much (again) for your help.

VJ
Jun 11 '08 #4
vljones
18
If the above code does not get it try it this way:

Expand|Select|Wrap|Line Numbers
  1. Select tbl_Est.[Num_ClaimNo], tbl_Est.[Date_Date], tbl_Est.[Num_Estimate], Max("tbl_Est.[Date_Date]") as MaxClaimDate, tbl_Bord05.[Num_ClaimNo]
  2. From tbl_Est, tbl_Bord05
  3. Where tbl_Est.[Num_ClaimNo] = tbl_Bord05.[Num_ClaimNo] 
  4. Group By tbl_Est.[Num_ClaimNo] 
  5. Having tbl_Est.[Date_Date] =  Max("tbl_Est.[Date_Date]")
  6. Order By tbl_Est.[Num_ClaimNo]

Unfortunately this did not work either, producing the following error.

You tried to execute a query that does not include the specified expression <name> as part of an aggregate function. (Error 3122)

VJ
Jun 11 '08 #5
vljones
18
Unfortunately this did not work either, producing the following error.

You tried to execute a query that does not include the specified expression <name> as part of an aggregate function. (Error 3122)

VJ
Have figured it out another way that works better, but thanks anyway for your help.

VJ
Jun 11 '08 #6
puppydogbuddy
1,923 Expert 1GB
Have figured it out another way that works better, but thanks anyway for your help.

VJ
VJ,
It would be helpful to others if you would post your solution. You would get the above mentioned errors if nulls were encountered in the date or claim no fields. So maybe if the above syntax provided for nulls, it may have worked.
Jun 11 '08 #7

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

Similar topics

3
by: Rich Bernat | last post by:
We have vending machines which are serviced by emptying the money inside the machine and placing it into numbered bags. Each bag is numbered independently of the machines. Each machine has a...
4
by: lukeargent | last post by:
Hi All, I have come across some rather weird error that I can only assume is something to do with my ADP file connecting to SQL Server 2000. I'm using Access XP as my front end. In simple...
4
by: gps | last post by:
I'm trying to use Dmax to dip into a my invoice header table and pull the maxium invoice number out of it. I'm running Access 2007 on Vista Business, but had the same prob with Access 2003 on...
4
by: Ed Marzan | last post by:
Greetings, I have a query that returns varying prices for the same item in the following manner. Item1 Price1 Item1 Price2 Item1 Price3 Item1 Price4
2
by: joeyrhyulz | last post by:
Hi, I'm trying to make a very simple update statement (in Oracle) in jet sql that seems much more difficult than it should be. The root of my problem is that I'm trying to update a field on a...
3
by: DancingDave | last post by:
Can anyone tell me why MS Access produces #Error for MaxDate in all the rows in this query? SELECT NAMES., DMax("",""," = " & NAMES.) AS MaxDate FROM INNER JOIN XREF ON NAMES. = XREF.; When I...
1
by: nrtyme | last post by:
Hello, I need to add several new records to Table2 from Table1. Table2 contains a field called that needs to be the previous maximum value of incremented by 1. Below is my code but i keep...
7
by: kstevens | last post by:
Lets say i have 2 tables (ok i really do). One is tblShipping, the other is tblShippingDetails. I need to run a query to find all of the maximum values of a qty backordered, so that i can find out...
21
by: DanicaDear | last post by:
I have a report named "rptHOTSTICKS_EXPIRING" based on a query named "HOSTICKS_SHIPPING_REPORT Query". The query contains these fields: ORDER_NUM (text) CUST_NUM (text) Name, address, contact...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...
0
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,...
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,...

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.