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 |
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2009-04-17 : 22:15:16
|
Hi,My table as follow,tblEmployerTrnxID| EmployerID| setRR| CrtDte | UpdDte------------------------------------------------------1 | S0852 | jui | 4/12/2009 | 2 | P0004 | jui | 6/12/2008 | 7/12/20083 | N0003 | mik | 11/23/2008 | 8/3/20094 | S0852 | jui | 10/12/2008 | 2/12/20095 | P0004 | jui | 10/12/2008 | 2/12/2009Hint1. CrtDte will set, after perform insert statement - only 12. UpdDte will set, after perform update statementBased on EmployerID, how did i list all latest record? As a result my expected result as 1 | S0852 | jui | 4/12/2009 | 3 | N0003 | mik | 11/23/2008 | 8/3/20095 | P0004 | jui | 10/12/2008 | 2/12/2009 |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-04-17 : 23:55:00
|
Your output should be :1 | S0852 | jui | 4/12/2009 | 3 | N0003 | mik | 11/23/2008 | 8/3/20094 | S0852 | jui | 10/12/2008 | 2/12/20095 | P0004 | jui | 10/12/2008 | 2/12/2009 First Verify this is what you are looking for . |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-04-18 : 15:25:37
|
[code]SELECT t.*FROM YourTable tINNER JOIN (SELECT EmployerID,MAX(COALESCE(UpdDte,CrtDte)) AS Latest FROM YourTable GROUP BY EMployerID)t1ON t1.EmployerID=t.EmployerIDAND t1.Latest=COALESCE(t.UpdDte,t.CrtDte)[/code] |
|
|
|
|
|