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.
| Author |
Topic |
|
luridjester
Starting Member
2 Posts |
Posted - 2011-03-16 : 11:05:14
|
| I've got a query that I run periodically but I'm finding some issues with it that I've been unable to resolve on my own.I've simplified the output to show what I'm trying to get at, but I'm trying to pull distinct values for the employee name, their employee number and the most recent DateIn value so the second entry for Bob should (ideally) be left off since a more recent entry is available.EmpName EmpNum DateInBob 1234 3/15/2011Bob 1234 3/14/2011Jim 2345 3/15/2011Sue 3456 3/15/2011So here's an extremely basic version of my query:Select distinctEmpName,Empnum,DateInFrom EmpDBWhere DateIn >= 1/1/2011Group ByEmpName,Empnum,DateInThanks in advance |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-03-16 : 11:35:21
|
| Select EmpName,Empnum,MAX(DateIn) as DateInFrom EmpDBWhere DateIn >= 1/1/2011Group ByEmpName,Empnum JimEveryday I learn something that somebody else already knew |
 |
|
|
luridjester
Starting Member
2 Posts |
Posted - 2011-03-16 : 12:04:13
|
quote: Originally posted by jimf Select EmpName,Empnum,MAX(DateIn) as DateInFrom EmpDBWhere DateIn >= 1/1/2011Group ByEmpName,Empnum JimEveryday I learn something that somebody else already knew
I swear I tried that and it wasn't working, but now when I do it again it's working fine. Thanks for that, I expected it to be much more complicated than it was after looking at some of the threads with similar questions. |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-03-16 : 12:15:01
|
| You're welcome. I bet you included the DateIn in your group by column in your original query.JimEveryday I learn something that somebody else already knew |
 |
|
|
|
|
|
|
|