UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

> SQL Question    
 
   
accessdbguru
post Jan 19 2009, 02:28 PM
Post #1

UtterAccess Addict
Posts: 220
From: Houston, TX



I want help in the sql statement to pull 3 columns from a table which are
ID, Max(CalibDueDate), DoneBy from (Max(CalibDueDate).

Please see the attached Sample Data.
thanks for all the help,
Sam
Attached File(s)
Attached File  SQLQuestion.zip ( 28.64K ) Number of downloads: 5
 
Go to the top of the page
 
+
 
Start new topic
Replies (1 - 4)
jzwp11
post Jan 19 2009, 03:31 PM
Post #2

UtterAccess VIP
Posts: 4,236
From: Dayton, OH



Trying to do something with a null field involved can cause problems. I was going to suggest creating a max query, to find the max date for each ID

The only way it groups correctly is to ignore the record with the Null date
query name: qryMax
SELECT SampleData.ID, Max(SampleData.CalibDueDate) AS MaxOfCalibDueDate
FROM SampleData
WHERE Not ISNull(sampledata.calibduedate)
GROUP BY SampleData.ID;


Then I would link this query back to the original table in a second query

SELECT SampleData.ID, SampleData.CalibDueDate, SampleData.DoneBy
FROM SampleData INNER JOIN qryMaxDate ON (SampleData.CalibDueDate = qryMaxDate.MaxOfCalibDueDate) AND (SampleData.ID = qryMaxDate.ID);

This unfortunately does not give you the desired output because of the Null date field.

I would think that calibration due date is best handled by storing the last calibration date and the calibration frequency (in days). Therefore to get the calibration due date you would just add the frequency to the last calibration date. Since the due date is a calulated value, you would not store it.
Go to the top of the page
 
+
vtd
post Jan 19 2009, 03:32 PM
Post #3

Retired Moderator
Posts: 19,667



You transposed one of the numbers in the JPG file which didn't help.

Try one of the techniques in The Access Web article.
Go to the top of the page
 
+
accessdbguru
post Jan 19 2009, 03:47 PM
Post #4

UtterAccess Addict
Posts: 220
From: Houston, TX



Van,
You are right I missed ID # 4534.
thanks!
Go to the top of the page
 
+
vtd
post Jan 19 2009, 05:32 PM
Post #5

Retired Moderator
Posts: 19,667



You're welcome... Glad we could help...
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 23rd May 2013 - 01:58 AM