Query Question...

1

116

I have a query that I used SQL on, and I am trying to get 'MAX' to work on a
Date field (DATERANGE) so the results will always pull up the must current.
Can someone take a look at this.

SELECT EntryID, DATERANGE, CLN, NAME, SHIFT, REGT, OT, DBLT, ITS
FROM t_Employee_Hrs ORDER BY DATERANGE ASC,CLN ASC

Thanks
David
 
J

Jon Spivey

Hi,
This is the culprit
ORDER BY DATERANGE ASC,CLN ASC

There's 2 ways to sort dates/numbers etc
Ascending ASC - 1,2,3,4
Descending DESC - 4,3,2,1

If you don't specify one or the other ASC is the default. To get the newest
date first you would need
ORDER BY DATERANGE DESC

Cheers,
Jon
http://MyMobileDeal.com
 
1

116

Thanks Jon for the quick response. What I have are weekly payroll hours.
The DATERANGE is a Saturday date. So I am trying to use the MAX feature to
grab ALL records with that Week Ending date. It happens that it will always
be my MAX.

David
 
J

Jon Spivey

Sorry, misunderstood the question. I think you want

select * from table where daterange = (select max(daterange) from table)

This will pull up all the records that have the highest value for daterange

Cheers,
Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top