Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to: Select most recent date?

Author  Topic 

munkdogg
Yak Posting Veteran

53 Posts

Posted - 2009-01-07 : 14:49:56
good morning,

The data in my table appears as follows;

Person EnteredBy Location Hours Date SysID
1 1 1 1.50 11/27/2008 1
1 1 1 0.75 12/8/2008 1
2 1 1 8.25 12/22/2008 2


and so on....

I have an existing script which compiles the Person, hours, and number of records - but I've been asked to also include the most recent date of any records per that user (Person).

I'm comfortable using DateDiff and GetDate, but unsure as to how this request could be met using those two functions.

Can someone please point me in the right direction?

Thank you!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-07 : 14:50:48
Could you show us the expected result set using the sample data that you posted?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

munkdogg
Yak Posting Veteran

53 Posts

Posted - 2009-01-07 : 14:59:23
quote:
Originally posted by tkizer

Could you show us the expected result set using the sample data that you posted?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog




It would appear like this;

User Total Hours Number of Entries Most recent Entry
1 2.25 2 12/8/2008
2 8.25 1 12/22/2008
Go to Top of Page

munkdogg
Yak Posting Veteran

53 Posts

Posted - 2009-01-07 : 16:02:59
I got it to work!

Simply included the MAX (Date) variable, got exactly what I needed. Thanks all.
Go to Top of Page
   

- Advertisement -