See if this will not identify the max record by Audtrandate (Time) and return that row to you.
Main Topics
Browse All TopicsI tried to extract latest records from a table but was unable to filter out the duplicate records (as the table is a transaction log, it captures transaction with variations in 2 fields, namely audtrantime and Qty).
Example, one of the following records is to be excluded but I was unable to do so (ie record 1 should be filtered out and record 2 should be extracted):
CourseID SessionDate SesSionNo Qty AudtranDate Audtrantime
Theory1 05/May/2009 10 10 10/Apr/2009 09:30:45
Theory1 05/May/2009 10 9 10/Apr/2009 13:15:30
My intended result is to extract record 2 and filter out record 1, so far, I was unable to do so, any pointers (scrip attached)?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: aneeshattingalPosted on 2009-06-01 at 22:33:43ID: 24524111
Select CourseID,SesDate,sesno,Qty ,MAX(CAST( audtrandat e +' '+Audtrantime as datetime) )
from tblCourseSchAudit with(NoLock)
where CourseID = 'Theory1'
and SesDate between '01/05/2009' and '31/05/2009'
and AudTranDate < '16/043/2009'
Group By CourseID,SesDate,sesno,Qty